0

Please suggest the right way of doing the following.

data_tr['loss'] = data_tr['loss'].apply(lambda x:x**0.25)

<ipython-input-368-59c3c700212e>: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

data_tr['loss'] = data_tr['loss'].apply(lambda x:x**0.25)
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
  • 1
    `data_tr=data_tr.copy()` before that line. Also, replace that line with `data_tr['loss'] *= .25` would be much faster (you still need the copy though). – Quang Hoang Mar 25 '21 at 04:36

1 Answers1

0

Have you tried what's suggested?

data_tr.loc[:,'loss'] = data_tr.loc[:,'loss']**0.25
norie
  • 9,609
  • 2
  • 11
  • 18