I would like to replace values in a particular column of a data frame. I tried several methods but they either do not work or they elicit a SettingWithCopyWarning. I would like to understand what the proper way would be. I found some older questions but I think they are based on an outdated syntax and do not reflect the current 'good practice'.
At first I tried
df.loc[:,['UNDERINFL']].replace(['N','Y'],['0', '1'], inplace = True)
This does not elicit any error or warning but it also does not replace anything.
Then I tried
df.loc[:,['UNDERINFL']] = df.loc[:,['UNDERINFL']].replace(['N','Y'],['0', '1'])
This works but it also throws the SettingWithCopyWarning and encourages me to use .loc = value, which I thought I am doing.
Can someone tell me the proper way to do this?