fillna and copy of a slice problem even after .loc

Viewed 35

I am trying to fillna a column of dataframe like the following,

df['temp'] = df['temp'].fillna(method='ffill')

and I am getting,

var/folders/qp/lp_5yt3s65q_pj__6v_kdvnh0000gn/T/ipykernel_10842/2929940072.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['temp'] = df['temp'].fillna(method='ffill')

I revised the code to the following but I am still getting the same error. Do you have any suggestions?

df.loc[:,'temp'] = df['temp'].fillna(method='ffill')
0 Answers
Related