I have a dataframe with 3 columns(A,B,C). I wanted to update column C
with column A
when column B
=22. I have written update statement like this, but it's updating NaN
for non matching rows. Could you tell me how to update data in dataframe?
df = pd.DataFrame(data=[[10,20,30],[11,21,31],[12,22,32]], columns=['A','B','C'])
df.C = df[df.B==22].A
Let us try mask
df.C.mask(df.B==22, df.A,inplace=True)
df
A B C
0 10 20 30
1 11 21 31
2 12 22 12
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