I have a pandas dataframe like the following:
Col1 Col2 Col3
0 A 7 NaN
1 B 16 NaN
1 B 16 15
What I want to do is to swap Col2 with Col3 where the value of Col3 is NaN
. Based on other posts and answers on SO, I have this code so far:
df[['Col2', 'Col3']] = df[['Col3', 'Col2']].where(df[['Col3']].isnull())
But this does not seem to be working properly and gives me the following:
Col1 Col2 Col3
0 A NaN NaN
1 B NaN NaN
1 B NaN NaN
Is there something that I might be missing here?
Update: My desired output looks like:
Col1 Col2 Col3
0 A NaN 7
1 B NaN 16
1 B 16 15
Thanks