0

A warning keep appear on the following code, why and how to solve it? What's wrong with it?

below is the error:

\pandas\core\series.py:4509: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  return super().replace(

below is the code:

for tpepn, alopn in tine_convertion.items():
    wip_df['items'].replace({tpepn:alopn}, inplace=True)
tax evader
  • 2,082
  • 1
  • 7
  • 9
pukiwawa
  • 1
  • 1
  • 1
    `wip_df` was created in a way that it is still linked to some other DataFrame. This is letting you know that you are working on a copy and attempting to assign a new value to a copy which is not linked to the initial dataframe. At some point before this you did something like `wip_df = df[some columns or filter]` where it should have been something like `wip_df = df[some columns or filter].copy()` – Henry Ecker Aug 25 '21 at 05:23
  • also note that you can use a dictionary to replace items in a dataframe without looping over them using: wip_df['items'].replace(tine_convertion, inplace=True). Generally it is best to avoid for loops when working with dataframes as they are very slow – Daniel Redgate Aug 25 '21 at 05:35

0 Answers0