OneHotEncoder Help

Before applying onehotencoder do we need to first factorize or apply label encoder as on using below code where i am trying to apply onehot encoder on multiple columns at once getting below error
Error “int() argument must be a string, a bytes-like object or a number, not ‘Timestamp’”

Categorical boolean mask

categorical_feature_mask = demand_sales_data.dtypes==object

import OneHotEncoder

from sklearn.preprocessing import OneHotEncoder

instantiate OneHotEncoder

ohe = OneHotEncoder(categorical_features = categorical_feature_mask, sparse=False )

categorical_features = boolean mask for categorical columns

sparse = False output an array not sparse matrix

apply OneHotEncoder on categorical feature columns

X_ohe = ohe.fit_transform(demand_sales_data) # It returns an numpy array

Hi,
In some case the time/date will not be in datetime format it may be in string, so you need to make it into correct data type.
You can use the below to convert to datetime format.

`pd.to_datetime(“2018-09-01”)

All the best!