+

Python | Pandas Period.weekday

Period.weekday Pandas Period.weekday returns an integer value indicating the day of the week of this period object.

Syntax: Period.weekday

Parameters: None

Return: weekday

Example # 1: Use the Period.weekday attribute to find the day of the week in a given period object.

# import pandas as pd

import pandas as pd

  
# Create Period object

prd = pd.Period (freq = `S` , year = 2000 , month = 2 , day = 22 ,

  hour = 8 , minute = 21 , second = 24 )

  
# Print Period object

print (prd)

Output:

We will now use the Period.weekday attribute to find the day of the week in the Period.weekday object.

# return the day of the week
prd.weekday

Output:

As we can see from the output, the Period.weekday attribute returned 1 indicating that this period is the first day of the week.

Example # 2: Use the Period.weekday attribute to find the day of the week in a given period object.

# import pandas as pd

import pandas as pd 

 
# Create Period Object

prd = pd.Period (freq = ` S` , year = 2006 , month = 10 ,

hour = 15 , minute = 49 , second = 17 )

 
# Print object

print (prd)

Output:

Now we will use the Period.weekday attribute to find the day of the week in the Period.weekday object.

# return the day of the week
prd.weekday

Output:

Like us as seen from the output, the Period.weekday attribute returned 6, indicating that the given period is the sixth day of the week.

Get Solution for free from DataCamp guru