Using Scikit-Learn OneHotEncoder with a Pandas DataFrame
Using Scikit-Learn OneHotEncoder with a Pandas DataFrame Question: I’m trying to replace a column within a Pandas DataFrame containing strings into a one-hot encoded equivalent using Scikit-Learn’s OneHotEncoder. My code below doesn’t work: from sklearn.preprocessing import OneHotEncoder # data is a Pandas DataFrame jobs_encoder = OneHotEncoder() jobs_encoder.fit(data[‘Profession’].unique().reshape(1, -1)) data[‘Profession’] = jobs_encoder.transform(data[‘Profession’].to_numpy().reshape(-1, 1)) It produces the …