概述
我希望有人有洞察力.我敢肯定它并不复杂.
我有一个df我正在检查一列中的值 – 如果该值是’n / a'(作为字符串,而不是.isnull()),将其更改为另一个值.
Full_Names_Test_2 [‘MarketCap’] ==’n / a’
收益:
70 True 88 False 90 True 145 True 156 True 181 True 191 True 200 True 219 True 223 False Name: MarketCap,dtype: bool
这部分是有效的.
但是这个:
Full_Names_Test_2['NewColumn'] = np.where(Full_Names_Test_2['MarketCap'] == 'n/a',7)
收益:
ValueError: either both or neither of x and y should be given
到底是怎么回事?
np.where(Full_Names_Test_2['MarketCap'] == 'n/a',7) # should be np.where(Full_Names_Test_2['MarketCap'] == 'n/a',Full_Names_Test_2['MarketCap'],7)
请参阅np.where
文档.
Full_Names_Test_2['MarketCap'].where(Full_Names_Test_2['MarketCap'] == 'n/a',7)
总结
以上是编程之家为你收集整理的python – np.where在我的熊猫中不起作用全部内容,希望文章能够帮你解决python – np.where在我的熊猫中不起作用所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧