How to convert a datetime Pandas column to day of week?

In this short tutorial we’ll show how to use Python to easily convert a Pandas DataFrame datetime column and get instead the name of the weekday.

Create an example DataFrame

Let’s assume the following DataFrame:

import pandas as pd

#Define Data
office = ['Denver','Paris', 'Denver', 'London' ]
full_date = ['1-15-2022 13:45:00', '4-8-2022 08:45:00', '2-23-2022 12:45:00', '4-7-2022 13:46:00']
salary = [143, 153, 128, 149]
hiring_dict  = dict( office=office,hire_date=full_date,salary = salary)

# Create DataFrame
hiring_df = pd.DataFrame(data=hiring_dict)

Let’s look at the Data types of the DataFrame:


Here’s the result we’ll get. It looks like we should first cast the hire_date column to datetime64 first.

office       object
hire_date    object
salary        int64
dtype: object

Convert datetime to day of week

If we’ll try to convert the hire_date column to day of the week we’ll receive an error.


Pandas will throw the following message:

AttributeError: Can only use .dt accessor with datetimelike values

As mentioned above, before proceeding we first need to ensure our column data type is datetime. We can then use the dt accessor to find date values. Initially we’ll find the value of the day of the week of each observation in our data:

hiring_df['hire_weekday'] = \

Alternatively, we can use the following:

hiring_df['hire_weekday'] = \ pd.to_datetime(hiring_df['hire_date']).dt.day_of_week

One more option is to use the astype method:

hiring_df['hire_weekday']= \

All the above will render the weekday number as shown below:

0Denver1-15-2022 13:45:001435
1Paris4-8-2022 08:45:001534
2Denver2-23-2022 12:45:001282
3London4-7-2022 13:46:001493

Find the day of week name

In a similar fashion we can use the dt.day_name() function to retrieve the name of the week day.

hiring_df['hire_day_name'] = \

Create a column with month names

As we have seen above,we ca use the dt accessor in order to extract several date/time values. In a similar fashion, we’ll now go ahead and extract the month name into a new DataFrame column:

hiring_df['hire_month'] = \ pd.to_datetime(hiring_df['hire_date']).dt.month_name()

And here are our complete DataFrame values:

0Denver1-15-2022 13:45:001435SaturdayJanuary
1Paris4-8-2022 08:45:001534FridayApril
2Denver2-23-2022 12:45:001282WednesdayFebruary
3London4-7-2022 13:46:001493ThursdayApril