pandas.Series.interpolate

Series.interpolate(method='linear', axis=0, limit=None, inplace=False, limit_direction='forward', downcast=None, **kwargs)[source]

根据不同的方法内插值。

请注意,对于具有MultiIndex的DataFrames / Series,仅支持method='linear'

参数:

方法:{'linear','time','index','values','nearest','zero'

'slinear','quadratic','cubic','barycentric','krogh','polynomial','spline','piecewise_polynomial','from_derivatives','pchip','akima'}

  • 'linear':忽略索引并将值视为等间距。这是MultiIndexes支持的唯一方法。默认
  • 'time':插值对每日和更高分辨率数据进行插值以间隔给定的间隔长度
  • 'index','values':使用索引的实际数值
  • 'nearest','zero','slinear','quadratic','cubic','barycentric','polynomial'传递给scipy.interpolate.interp1d“多项式”和“样条”都需要指定顺序(int)。 df.interpolate(method ='polynomial',order = 4)。这些使用指数的实际数值。
  • 'krogh','piecewise_polynomial','spline','pchip'和'akima'都是类似名称的scipy插值方法的包装器。这些使用指数的实际数值。有关其行为的详细信息,请参阅scipy文档此处#noqa 和此处#noqa
  • 'from_derivatives'指的是在scipy 0.18中替换“分段多项式”插值法的BPoly.from_derivatives

版本0.18.1中的新功能:添加了对'akima'方法的支持添加了interpolate方法'from_derivatives',它替换了scipy 0.18中的'piecewise_polynomial'向后兼容scipy

axis:{0,1},默认为0

  • 0:逐列填充
  • 1:逐行填充

limit:int,默认值无。

要填充的连续NaN的最大数量。

limit_direction:{'forward','backward','both'},默认为“forward”

如果指定limit,将在此方向填充连续NaN。

版本0.17.0中的新功能。

inplace:bool,default False

如果可能,请更新NDFrame。

downcast:可选,“推断”或无,默认为无

如果可能的话。

kwargs:要传递给插值函数的关键字参数。

返回:

相同形状的系列或数据帧插入在NaNs

也可以看看

reindexreplacefillna

例子

填充NaNs

>>> s = pd.Series([0, 1, np.nan, 3])
>>> s.interpolate()
0    0
1    1
2    2
3    3
dtype: float64
Scroll To Top