0
$\begingroup$

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.

$\endgroup$

1 Answer 1

0
$\begingroup$

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'])
$\endgroup$
1
  • $\begingroup$ indeed, this worked well and created as many columns as the cardinality of the label. $\endgroup$
    – Stefano
    Commented Apr 8, 2022 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.