假设我有一个数据集,比如:
> NaN NaN NaN 12 NaN NaN NaN NaN 10 NaN NaN NaN NaN 8 NaN 6 NaN
我希望将值尽可能均匀地分布在它们周围的NaN
s的值之间。例如,值12应该考虑到它们周围的NaNs
,并均匀地分布它们,直到它碰到第二个非NaN
值的NaN
例如,前12个应该只考虑他最近的nan。在
^{pr2}$输出应为:
2 2 2 2 2 (Distributed by the 12)
2 2 2 2 2 (Distributed by the 10)
2 2 2 2 (Distributed by the 8)
2 2 2 (Distributed by the 6)
> NaN NaN NaN 12 NaN NaN NaN NaN 10 NaN NaN NaN NaN 8 NaN 6 NaN
> 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
我最初考虑使用平滑器,比如Pandas中的插值函数。它不一定是无损的,这意味着我们可以在过程中损失或得到更多。有没有库可以执行这种分发而不是使用有损平滑器?在
您可以使用^{} 、^{} 和{a3},最后使用^{} 。在
短版:
为了说明发生了什么,请创建您的
^{pr2}$df
其中
x
是您给出的系列。现在:相关问题 更多 >
编程相关推荐