0

My code is wornking fine, but this messages shows in some commands and I can't figure it out.

df.loc[:,'Piso Salarial'] = df['Piso Salarial'].apply(lambda x: x.replace('.',''))

In this line I am trying to replace '.' for '' so I can convert strings to float on the next command. When I do this, a message is shown:

/tmp/ipykernel_287/2001347796.py:1: 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.loc[:,'Piso Salarial'] = df['Piso Salarial'].apply(lambda x: x.replace('.',''))

I tried to use .loc on the dataframe column with the apply. I tried using .copy()

But the message is still on

Arthur
  • 1
  • At some point _before_ this provided code you have unsafely subset your DataFrame. Either `new_df = df[cols]` or `new_df = df[mask]` when it should have been `new_df = df[cols].copy()` or `new_df = df[mask].copy()` The warning is letting you know that `df[mask]['col'] = value` may not work because `df[mask]` may produce a copy and recommends that you use `df.loc[mask, 'col'] = value` but that message is not clear here since you're doing something like `new_df = df[mask]` then later doing `new_df[col] = value` which looks to pandas like a (deferred) `df[mask][col] = value` call. – Henry Ecker Mar 23 '22 at 22:44

0 Answers0