无法分配“ nan”/np中的空价值。
我正在尝试将我的“ np。”条件中的空单元(空白/nan)分配给我的熊猫数据框架,但似乎没有任何用途。
这样做的原因是要运行fillna,ffill在缺失值上。
np.Where代码:
df['x'] = np.where(df['y']>0.05,1,np.nan)
填充代码:
df['x'] = df['x'].fillna(method="ffill")
有人知道我要去哪里了吗?
I'm trying to assign an empty cell (blank/nan) in my "np.where" condition to my pandas dataframe, but nothing seems to work.
The reason for this is to run fillna,ffill on the missing values.
Np.Where code:
df['x'] = np.where(df['y']>0.05,1,np.nan)
Fillna code:
df['x'] = df['x'].fillna(method="ffill")
Anybody know where I'm going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够使用
pandas.na
而不是fillna
来修复它:
I was able to fix it using
pandas.NA
instead whichfillna
, for some reason, recognizes as blanks to fill withffill
Fix:
这条代码有效:
df ['x'] = np.Where(df ['y']> 0.05,1,np.nan)
只需删除右边的不需要的parathess
this line of code works:
df['x'] = np.where(df['y']>0.05,1,np.nan)
just remove the unneeded paratheses in the right