df = pd.DataFrame({'a':[1,2,3],'b':[1,3,5]})
a b
0 1 1
1 2 3
2 3 5
when I use df.at[df['a']==1] it report error ValueError: Invalid call for scalar access (getting)!
but when I use df.at[df['a']==1,'b'] = 0 it works
a b
0 1 0
1 2 3
2 3 5
When you call the Boolean just do simple slice will work.
df[df['a']==1]
a b
0 1 1
For your error .at only accept the pair index and col combination, notice the index and col should be int or array only contain one True value
The reason why you df.at[df['a']==1,'b'] = 0 work, since df['a']==1 return an array with only one True, which just same as input one index number.
If you change df.at[df['a'].isnull(),'b'] = 0 this will fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With