I have a problem with np.where using Pandas that drives me crazy and I cannot solve the problem through google, documentation, etc.
I hope someone has an understanding. I am sure it is not difficult.
I have df where I check the value in one column - and if that value is "n / a" (as a string, and not as in .isnull ()), changing it to another value.
Full_Names_Test_2['MarketCap'] == 'n/a'
returns:
70 True 88 False 90 True 145 True 156 True 181 True 191 True 200 True 219 True 223 False Name: MarketCap, dtype: bool
for this part to work.
but this:
Full_Names_Test_2['NewColumn'] = np.where(Full_Names_Test_2['MarketCap'] == 'n/a', 7)
returns:
ValueError: either both or neither of x and y should be given
What's happening?
source share