滚动平均值来填充 NaN
我得到了这个函数来填充 main_df 的 NaN 单元格。计算出每一行的渐进滚动平均值后,我会从每个 NaN 级别的平均值流中选取值,以便替换 main_df
单元格中的那些 NaN。
这是我的试用:
main_df = pd.DataFrame({'a':[1,1,2,3,4,56,6],'b':[2,3,2,np.nan,4,3,6],'c':[1,1,2,3,4,56,np.nan]})
for i in range(len(main_df)):
main_df.iloc[i] = main_df.iloc[i].fillna(value=main_df.iloc[i].ewm(span=1).mean())
有什么建议让它发挥作用吗?
I got this function for fill main_df
's NaN cells. After had calculate the progressive rolling mean from every row, I'd then pick the value from the mean stream at each level of NaNs in order to substitute with those NaNs in the main_df
cells.
Here is my trial:
main_df = pd.DataFrame({'a':[1,1,2,3,4,56,6],'b':[2,3,2,np.nan,4,3,6],'c':[1,1,2,3,4,56,np.nan]})
for i in range(len(main_df)):
main_df.iloc[i] = main_df.iloc[i].fillna(value=main_df.iloc[i].ewm(span=1).mean())
Any suggestions to let it works ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最后仔细检查了我的功能是否有效:
我将“c”中的 nan 替换为与 nan 相同级别的 ema2 值
I had final doublcheck my function works :
I got substitution of nan in 'c' with values of ema2 at same level of nan