Correct way to set value on a slice in pandas [duplicate] Correct way to set value on a slice in pandas [duplicate] python python

Correct way to set value on a slice in pandas [duplicate]


This is a very common warning from pandas. It means you are writing in a copy slice, not the original data so it might not apply to the original columns due to confusing chained assignment. Please read this post. It has detailed discussion on this SettingWithCopyWarning. In your case I think you can try

data.loc[data['name'] == 'fred', 'A'] = 0