One hot encoding with Keras

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.

Topic one-hot-encoding keras neural-network

Category Data Science


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'])

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.