How to check if a date is the last day of the quarter in pandas

Overview

The .is_quarter_end attribute of Pandas.Timestamp (an equivalent of Python's Datetime object) is used to check if the date is the last day of the quarter or not.

Syntax

Timestamp.is_quarter_end
Syntax for the .is_quarter_end attribute

Parameters

This attribute takes no parameter value.

Return value

This attribute returns a Boolean value indicating if the date is the last day of the quarter. It returns True if it is the last day and False if not.

Example

# A code to illustrate the .is_quarter_end attribute in Pandas
# importing the pandas library
import pandas as pd
# creating a Timestamp object
a = pd.Timestamp(2022, 6, 30)
b = pd.Timestamp(2022, 6, 29)
# checking if date is the last day of the quarter
print(a.is_quarter_end)
print(b.is_quarter_end)

Explanation

  • Line 3: We import the pandas library.
  • Line 6-7: We create Timestamp objects, a and b, representing the month of June.
  • Line 10: We obtained the result indicating if any of the dates is the last day of the quarter or not using the .is_quarter_end.

Free Resources