如何使用多个相邻点在 pandas 中进行插值?

问题描述 投票:0回答:1

如果我使用

df.interpolate
,它会在最后一个点和第一个点之间绘制直线。你能让它考虑几个邻居吗?

python pandas interpolation
1个回答
0
投票

用直线,不行。只有一种方法可以在两点之间画一条直线。

否则,是的,你可以。问题是你想要怎样?

如果您考虑:

     A    B
0  1.0  0.0
1  2.0  2.0
2  NaN  NaN
3  4.0  4.0
4  5.0  4.5

默认值

interpolate
给出相同的值:

df.interpolate()

     A    B
0  1.0  0.0
1  2.0  2.0
2  3.0  3.0  # only considering n-1/n+1
3  4.0  4.0
4  5.0  4.5

您可以使用多项式或样条插值:

df.interpolate(method='polynomial', order=2)

     A     B
0  1.0  0.00
1  2.0  2.00
2  3.0  3.25  # considering the neighbors
3  4.0  4.00
4  5.0  4.50
© www.soinside.com 2019 - 2024. All rights reserved.