I have a dataframe:
jb = pd.DataFrame([ ['No', 75, 2.0], ['Blofeld', 140, 1.9], ['Chiffre', 114, 1.7] ],
index=['b1', 'b5', 'b21'], columns=['Name', 'Weight', 'Height'])
Then if I do chained assignment as below, it won't change the original value in jb
. And it will also trigger SettingWithCopyWarning
.
jb[jb.Weight==75]['Height'] = 9
But if I switch the order of chained assignment, it will then change the original value in jb
, but still also trigger SettingWithCopyWarning
.
jb['Height'][jb.Weight==75] = 9
So the second code is still producing a copy but why it ends up modifying the original jb
?