I'm using hotEncoder for a column with 5 values witch gave me 5 columns (for Z). That's OK now I have another column with has 3 values but I got 2 columns instead of 3 in Z1 what I need to do in the code to fix that I'll get 3 columns in Z1?
also, I would like the explanation for the hotEncoder code. Why I have to use np.hstack here? Thank you very much!!
X = df.iloc[:, :-1].values
Y = df.iloc[:, -1].values
labelencoder_X5 = LabelEncoder()
labelencoder_X6 = LabelEncoder()
X[:, 5] = labelencoder_X5.fit_transform(X[:, 5])
X[:, 6] = labelencoder_X6.fit_transform(X[:, 6])
onehotencoder = OneHotEncoder(sparse=False)
Z= onehotencoder.fit_transform(X[:, [5]])
X = np.hstack(( Z, X[:,:5] , X[:,6:])).astype('float')
#handling the dummy variable trap
X = X[:, 1:]
onehotencoder = OneHotEncoder(sparse=False)
Z1= onehotencoder.fit_transform(X[:, [6]])
X = np.hstack(( Z1, X[:,:6] , X[:,7:])).astype('float')
#handling the dummy variable trap
X = X[:, 1:]