Given a particular date, it is possible to obtain the day of the week on which the date falls. This is achieved with the help of Pandas library and the to_datetime() method present in pandas.
In most of the datasets the Date column appears to be of the data type String, which definitely isn’t comfortable to perform any calculations with that column, such as the difference in months between 2 dates, the difference in time or finding the day of the week. Hence Pandas provides a method called
to_datetime() to convert strings into Timestamp objects.
We'll use the date format 'dd/mm/yyyy' Input : '24/07/2020' Output : 'Friday' Input : '01/01/2001' Output : 'Monday'
Once we convert a date in string format into a date time object, it is easy to get the day of the week using the method
day_name() on the Timestamp object created.
Example 1 : In this example, we pass a random date with the type ‘str’ and format ‘dd/mm/yyyy’ to the
to_datetime() method . As a result we get a Timestamp pandas object. Then we retrieve the day of the week by the Timestamp class’s
Example 2 : In the below example, dates of different formats have been converted to a Timestamp object and then their respective days of the week are retrieved using
day_name() method .
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Get Day from date in Pandas - Python
- How to print date starting from the given date for n number of days using Pandas?
- Python program to find day of the week for a given date
- Python - Convert day number to date in particular year
- Get Month from date in Pandas - Python
- Get month and Year from Date in Pandas - Python
- Python - Get Today's Current Day using Speech Recognition
- Python | Pandas Timestamp.day
- Python | Pandas DatetimeIndex.day
- Python | Pandas Period.day
- Python | Pandas PeriodIndex.day
- Python | Pandas Series.dt.day
- How to check whether the day is a weekday or not using Pandas in Python?
- Get Yesterday's date using Python
- Get current date using Python
- Get Current Date and Time using Python
- Python | Pandas Timestamp.date
- Python | Working with date and time using Pandas
- Python | Pandas DatetimeIndex.date
- Python | Pandas Series.dt.date
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.