1

I use apply function of pandas:

def get_value(x):
    #processing
    return x

df['result'] = df['data'].apply(get_value)

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

How to avoid this warning?

Chan
  • 3,605
  • 9
  • 29
  • 60
  • How to use 'loc' to do it? – Chan Jan 10 '18 at 08:39
  • I can only find the solution of "pd.options.mode.chained_assignment = None" – Chan Jan 10 '18 at 08:48
  • A lot depends on what is going on in get_value(). Just returning x from that function shouldn't throw this working. You could try creating a deep copy with `df['result'] = df['data'].apply(get_value).copy()` – David Rinck Jan 10 '18 at 14:58

0 Answers0