My task is to drop all rows containing NaNs and encode all the categorical variables inside of data.
I wrote a function that looks like
def preprocess_data(data):
data = data.dropna()
le = LabelEncoder()
data['car name'] = le.fit_transform(data['car name'])
return data
which takes a dataframe and returns a processed data. Running this function gives me a warning that says:
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
I don't quite get which part of my code is causing this and how to fix it.