在时间序列中插入缺失日期的最简单方法?

Easiest method to interpolate over missing dates in a time series?

我有一些 excel 的股票市场数据,涵盖过去 20 年左右,其中包含假期和周末的差距。我希望对那些缺失的日期进行插值以获得那些日子的近似股票指数。

我已使用 pandas 将两列读入 Python 并将它们分配给各自的变量。检测日期差距并在其中进行插值的最佳方法是什么?

Pandas有专门针对这种情况的方法:

df.interpolate() # will fill in based on the linear average of the before and after 
df.fillna(method='ffill') #  forward fill
df.fillna(method='bfill') #  backward fill