What is the Period.dayofweek() attribute in pandas?

Overview

The dayofweek() attribute in pandas is used to obtain the day of the week the given Period lies in. Monday is given as 0, Tuesday is given as 1, Wednesday is given as 2, and so on and so forth.

Syntax

Period.dayofweek
Syntax for the dayofweek attribute in Pandas

Parameters

The dayofweek, being an attribute, takes no parameter value.

Return value

The dayofweek attribute returns an integer representing the day of week from the given Period object.

Example

# A code to illustrate the dayofweek attribute
# importing the pandas library
import pandas as pd
# creating a Period object
a = pd.Period('2022-5-2 8:00', 'H')
# printing the day of the week
print(a.dayofweek)

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We create a Period object, a.
  • Line 9: We obtain the day of the week from the input, Period object, using the dayofweek attribute. We print the value to the console.

Free Resources