pandas - 识别最接近 null/sentinel 值的行

pandas - identify rows closest to null/sentinel value

使用以下格式的时间序列数据框,第一列作为索引:

08/11/2021, 100
08/12/2021, null
08/13/2021, null
08/14/2021, 160

我想对 return

进行插值
08/11/2021, 100
08/12/2021, 120
08/13/2021, 140
08/14/2021, 160

在不拔出 iterrows() 大锤的情况下获取最接近我的 df 中第一个和最后一个空值的行索引的有效方法是什么? (假设整个系列中可以有多个 null 跨度,我将在每次函数遇到 null 时重复此操作)

无需手动执行任何操作,只需使用 interpolate:

df.interpolate()