from sklearn import preprocessing
def labelencoder(dataframe) :
label_encoder = preprocessing.LabelEncoder()
dataframe= label_encoder.fit_transform(dataframe)
return dataframe
new_df['label'] = labelencoder(new_df['label'])
I am getting the following warning for the above code:
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
new_df['label'] = labelencoder(new_df['label'])
The code is working fine, it just shows this warning each time. Is there a solution?
I tried something like:
new_df.loc[:, 'label'] = labelencoder(new_df['label'])
But it didn't work, It still shows the warning
source https://stackoverflow.com/questions/76134989/setting-a-column-in-a-dataframe-to-new-values
Comments
Post a Comment