I am doing exact as the warning is asking me to do (i.e. using the loc indexer) and yet I am getting the same warning.
All the three approaches below give the warning.
scaler = MinMaxScaler()
df_train.loc[:, numeric_cols] = scaler.fit_transform(df_train[numeric_cols])
df_train.loc[:, numeric_cols] = scaler.fit_transform(df_train.loc[:, numeric_cols])
df_train[numeric_cols] = scaler.fit_transform(df_train[numeric_cols])
Full Warning:
C:\Users\ayush\anaconda3\lib\site-packages\pandas\core\indexing.py:1738: 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
self._setitem_single_column(loc, value[:, i].tolist(), pi)