How to return a numerical value for the day of the week in Pandas
Overview
The isoweekday() function in Pandas returns the day of the week represented by the Timestamp object, which is the equivalent of Python's DateTime object.
The isoweekday() function returns 1 if the day of the week is a Monday, 2 if Tuesday, 3 if Wednesday, and so forth until Sunday, which is represented by 7.
Syntax
Timestamp.isoweekday()
Syntax for the isoweekday() function
Parameter value
The isoweekday() function takes no parameter value.
Return value
The isoweekday() function returns an int representing the day of the week.
Example
# A code to illustrate the isoweekday() function in Pandas# Importing the Pandas libraryimport pandas as pd# Creating a Timestamp objecta = pd.Timestamp(2022, 4, 29)# Obtaining the day of the weekprint(a.isoweekday())
Explanation
- Line 3: We import the
pandaslibrary. - Line 6: We create a
Timestampobject,a. - Line 9: We use the
isoweekday()function to obtain and print the day of the week from the Timestamp object.
Note: The function gives an output value of
5, which represents that the date2022-04-29is aFriday.