I have a data frame called df
, with column A
.
I do the following code:
df['A'][df['A'] < 4] = np.NaN
I get the following message :
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
df['A'][df['A'] < 4] = np.NaN
bla.py:763: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
The code works, df
is changed after executing this line, so In practice it does not trying to change a copy of df
but the original df
Why do I get this warning ?
P.S : I looked at similar questions on stack overflow but could't find an answer