You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hidden chaining is another frequent issue responsible for SettingWithCopyWarning. It may occur the following way:
importpandasaspdimportnumpyasnpd= {'col1': [1, 2, 3], 'col2': [3, 4, np.nan]}
df=pd.DataFrame(data=d)
# This will cause the warningdf_no_na=df.dropna()
df_no_na.loc[:, 'new_column'] =df_no_na['col1'] +df_no_na['col2']
# This won't cause the warningdf_no_na=df.dropna().copy()
df_no_na.loc[: ,'new_column'] =df_no_na['col1'] +df_no_na['col2']
The point is that it also occurs when using df.loc[:, 'new_column'] so using .loc[] does not always prevent this warning from happening. The reason for the warning is obviously the same as in the example in your notebook, however i think this issue of chaining a get and an assignment is less obvious, hence 'hidden' :-).
The text was updated successfully, but these errors were encountered:
paulelvers
changed the title
Hidden Chaining
Hidden Chaining responsible for SettingWithCopyWarning
Nov 11, 2020
Hidden chaining is another frequent issue responsible for
SettingWithCopyWarning
. It may occur the following way:The point is that it also occurs when using df.loc[:, 'new_column'] so using .loc[] does not always prevent this warning from happening. The reason for the warning is obviously the same as in the example in your notebook, however i think this issue of chaining a get and an assignment is less obvious, hence 'hidden' :-).
The text was updated successfully, but these errors were encountered: