Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
python
communitycreator

How to get the ISO year, week number, and weekday in pandas

Onyejiaku Theophilus Chidalu

Overview

The isocalendar() function in Pandas returns the ISO year, week number, and weekday from a Timestamp object (an equivalent of Python's datetime object).

Syntax

The isocalendar() function takes the following syntax:

Timestamp.isocalendar()
The syntax for the isocalendar() function in pandas

Parameter value

The isocalendar() function takes no parameter value.

Return value

The isocalendar() function returns a 3-tuple holding the results.

Example

# A code to illustrate the isocalendar() function in Pandas
# importing the pandas library
import pandas as pd

# creating a date time object
my_date = pd.Timestamp('2022-04-29T7:48:52.192548651')


# obtaining the iso year, week number, and weeekday from the Timestamp
print(my_date.isocalendar())
Implement the isocalendar() function

Explanation

  • Line 3: We import the pandas module.
  • Line 6: We create a Timestamp (datetime) object and name it my_date.
  • Line 9: We obtain the ISO year, week number, and weekday from the given datetime object, my_date, using the isocalendar() function.

RELATED TAGS

pandas
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring