I have a large dataset (500k rows) where one column contains the weekday of the purchase. For now, it is in the 0-6 format (Mon-Sun) and I think I should one-hot encode it before training my sequential NN in Keras. It is not clear if I should do this in the dataset (transform the one column into 7 columns, manually or is there a Pandas function?) or I can just have that one column containing an array of length 7. The dataset is a Pandas Dataframe if it matters.
1 Answer
$\begingroup$
$\endgroup$
1
Pandas and skicit learn provides function to do the encoding.Sharing an example code using pandas dummies function
one_hot = pd.get_dummies(df['weekday'])
# Drop column weekday as it is now encoded
df = one_hot = pd.get_dummies(df['weekday'])
-
$\begingroup$ indeed, this worked well and created as many columns as the cardinality of the label. $\endgroup$– StefanoCommented Apr 8, 2022 at 10:22