我有一个np。在那里使用熊猫的问题让我疯狂,我似乎无法通过谷歌,文档等解决
我希望有人有洞察力。我相信这并不复杂。
我有一个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
怎么回事?
您需要传递布尔掩码和(两个)值列:
参见^{} 文档。
或者使用the ^{} Series method :
相关问题 更多 >
编程相关推荐