Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
communitycreator

How to return a numerical value for the day of the week in Pandas

Onyejiaku Theophilus Chidalu

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 library
import pandas as pd

# Creating a Timestamp object
a = pd.Timestamp(2022, 4, 29)

# Obtaining the day of the week
print(a.isoweekday())
Implementing the isoweekday() function

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We create a Timestamp object, 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 date 2022-04-29 is a Friday.

RELATED TAGS

pandas
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring