Open In App

Pandas Series dt.weekday | Find Day of the Week in Pandas

Last Updated : 07 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The dt.weekday attribute returns the day of the week. It is assumed the week starts on Monday, which is denoted by 0, and ends on Sunday which is denoted by 6.

Example

Python3




import pandas as pd
sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30',
               '2010-4-22 09:25', '2019-11-8 02:22'])
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
sr.index = idx
sr = pd.to_datetime(sr)
result = sr.dt.weekday
print(result)


Output:

dt.weekday attribute output

Syntax

Syntax: Series.dt.weekday 

Parameter: None 

Returns: Series of integers representing week day.

How to Get Day of Week as Integer from Date in Pandas Series

To extract the day of the week as an integer from a date in Pandas Series we use the Series.dt.weekday attribute of the Pandas library in Python.

Integer Range from 0 to 6, where 0 is the beginning meaning Monday, and 6 is the end meaning Sunday.

Let us understand it better with an example:

Example:

Use the dt.weekday attribute to return the day of the week for the given DateTime in the underlying data of the given Series object.

Python3




# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(pd.date_range('2012-12-12 12:12', periods = 5, freq = 'M'))
  
# Creating the index
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
  
# set the index
sr.index = idx
  
# Print the series
print(sr)


Output :

datetime series created

Now we will use the Series.dt.weekday attribute to return the day of the week for the given DateTime in the underlying data of the given Series object.

Python3




# return the day of week
result = sr.dt.weekday
  
# print the result
print(result)


Output :

day of the week returned

As we can see in the output, the Pandas dt.weekday attribute has successfully accessed and returned the day of the week in the underlying data of the given series object.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads