Q:

issue with oneHotEncoding

So i have a PandasDataFrame with categorical variables in a column which i want to one hot encode i've used the following code from an ML udemy course
from sklearn.preprocessing import OneHotEncoder
onehotencoder=OneHotEncoder(categorical_features=[10])
Y= onehotencoder.fit_transform(X).toarray()

However i get the following error 
ValueError: could not convert string to float:

A bit of information Y is converted to an object from a df using 
Y=df.iloc[:,:].values

I want to oneHotencode the 10th column of y which contains string values. The type of Y in variable explorer is object and if execute 
type(Y)

i get numpy.ndarray
I'm new to Pandas and sklearn and would really appreciate any help.

A:

There is an easy way to use one hot encoding in pandas and you can read about it in the following link:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html
The get_dummies method is easy and optimized for use in pandas Data Frames.
Good luck!

A:

It may be a late answer, but I got the same problem and below is the solution
# Don't use categorical_features=[10] in encoder init
from sklearn.preprocessing import OneHotEncoder
onehotencoder=OneHotEncoder()
Y= onehotencoder.fit_transform(X[:,[10]]).toarray()

