You can get this UserWarning if it df_maskedis a sub-DataFrame of another DataFrame. In particular, if the data was copied from the original DataFrame to df_masked, then Pandas throws UserWarning to warn you that the change df_maskedwill not affect the original DataFrame.
If you are not going to modify the original DataFrame, you can ignore UserWarning.
UserWarning . , df_masked.is_copy = False.
UserWarning , UserWarnings , , , . , UserWarning, -child-does-not-affect-the-parent , . , ,
pd.options.mode.chained_assignment = None
.
, () :
import pandas as pd
df = pd.DataFrame({'swallow':['African','European'], 'cheese':['gouda', 'cheddar']})
df_masked = df.iloc[1:]
df_masked.is_copy = False
df_masked.loc[:, 'swallow'] = 'forest'
, UserWarning, , ,
chained-indexing,
df.iloc[1:].loc[:, 'swallow'] = 'forest'
df, (, df.iloc[1:])
.