I have a filtered dataframe called df_final, I wanted two have additional tabs. For tab 2, I create a new column, then do filterig on that column and save it, then delete the created column and save it as tab 1. Here is the code:
df_final = df.query(query)
df_final["Duplicate"] = df_final.duplicated(subset=['DR/ER#'])
df_tab2 = df_final.loc[df_final['Duplicate']== True]
df_tab1 = df_final.drop(columns = ['Duplicate', 'DR/ER#'])
df_tab1.to_excel(writer, sheet_name = 'DR ER')
df_tab2.to_excel(writer, sheet_name = 'DR ER duplicates')
but I get this Error.
<ipython-input-6-4e0fc04c4f3a>:46: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df_final["Duplicate"] = df_final.duplicated(subset=['DR/ER#'])
Please, help me.
See the caveats in the documentation:...as the message suggested? Try searching SO with the error message, you should get plenty of information.Try using .loc[row_indexer,col_indexer] = value instead