Hello I am using the following function to convert all categorical values in a dataset into a numerical, but I want to convert this to use OneHotEncoder, How can do it?
def categorical_to_numerical(dataframe):
for col in dataframe.columns:
if str(dataframe[col].dtype) == 'category':
dataframe[col] = dataframe[col].astype("category").cat.codes
return dataframe
Thanks