0

I am trying to rename a column of a Dataframe but it is giving me a warning (SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame).

I have a dataframe with only two columns, 'u_id' (int64) and 'scores'(float64). My code looks like this:

df = df_scores.rename(columns = {'u_id': 'user_id'}, inplace = True)

I can't find a solution in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

The command worked completely fine a few weeks ago but is not working now. Can anyone please help?

Abir
  • 33
  • 5
  • Try to remove `inplace=True`. Or if you want to have both dataframes, df and df_scores, with the same values do in one line `df_scores.rename(columns = {'u_id': 'user_id'}, inplace = True) ` and in a new one `df = df_scores` – Giulio Mattolin Jan 29 '22 at 16:12

0 Answers0