Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

convert pandas datetime to day, weekday, month

#Convert datetime column/series to hour of the day. NB: Column must be in datetime format.
df['hour'] = df['column_name'].dt.hour
#Convert datetime column/series to day of the week
df['day'] = df['column_name'].dt.weekday
#Convert datetime column/series to month
df['month'] = df['column_name'].dt.month
#Convert datetime column/series to year
df['year'] = df['column_name'].dt.year
#NB: Weekday/Month will be in int. Eg. for months, January=1, February=2...etc,
 
PREVIOUS NEXT
Tagged: #convert #pandas #datetime #month
ADD COMMENT
Topic
Name
6+9 =