简体   繁体   English

在熊猫数据框中插入NaN无效

[英]Interpolating NaNs in pandas dataframe not working

I have the foll. 我有傻瓜。 dataframe: 数据框:

                vals 
2017-07-08  0.169524 
2017-07-09  0.167619 
2017-07-10  0.165714 
2017-07-11  0.163810 
2017-07-12  0.161905 

Based on Extend pandas datetime index to present date , I extend the index to present day and then I want to fill in values by interpolation. 基于将pandas datetime索引扩展到当前日期 ,我将索引扩展到当前日期 ,然后我想通过插值来填充值。 I do this: 我这样做:

df.interpolate(how='bicubic', inplace=True)

and get this: 并得到这个:

               vals
2017-07-11  0.163810
2017-07-12  0.161905
2017-07-13  0.161905
2017-07-14  0.161905
2017-07-15  0.161905

However, I want the last 3 values from 2017-07-13 to 2017-07-15 not to be the same as the value for 2017-07-12 but be based on whatever trend was happening over the last few values. 不过,我想从过去的3个值2017-07-132017-07-15不相同的值, 2017-07-12 ,但根据任何趋势是发生在过去的几个值。 How can I fix this? 我怎样才能解决这个问题?

What you are trying to do is actually extrapolation, not interpolation, and unfortunately pnd.DataFrame does not have a method for it. 您实际上想做的是外推而不是内插,不幸的是pnd.DataFrame没有它的方法。

You will need to define an extrapolation model, for example by fitting a polynomial curve from your known data and extrapolating it to the remaining index. 您将需要定义一个外推模型,例如通过从已知数据拟合多项式曲线并将其外推到剩余索引。 There is nice explanation on how to do this with time-series indexes over here . 这里有一个很好的解释,说明如何使用时间序列索引执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM