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 libraryimport pandas as pd# creating a Period objecta = pd.Period('2022-5-2 8:00', 'H')# printing the day of the weekprint(a.dayofweek)
Explanation
- Line 3: We import the
pandaslibrary. - Line 6: We create a
Periodobject,a. - Line 9: We obtain the day of the week from the input,
Periodobject, using thedayofweekattribute. We print the value to the console.