【问题标题】:Easiest method to interpolate over missing dates in a time series?在时间序列中插入缺失日期的最简单方法?
【发布时间】:2021-03-30 06:54:52
【问题描述】:

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

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

【问题讨论】:

    标签: python pandas interpolation


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 2013-05-23
      • 2020-10-22
      • 2022-01-15
      • 2017-03-06
      • 2011-04-03
      • 2020-04-12
      • 2015-06-19
      • 2018-05-21
      • 1970-01-01
      相关资源
      最近更新 更多