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

Overview

The is_month_end attribute in pandas.Timestamp (an equivalent of Python's DateTime object) is used to check if the given date is the last day of the month.

Syntax

Timestamp.is_month_end

Parameters

This attribute takes no parameter value.

Return value

This attribute returns a Boolean value. It returns True to indicate that the date is the last day of the month. Otherwise, it returns False.

Example

# A code to illustrate the .is_month_end attribute in Pandas
# importing the pandas library
import pandas as pd
# creating Timestamp objects
a = pd.Timestamp(2022, 4, 19)
b = pd.Timestamp(2022, 4, 30)
# checking if the dates is or are the last day of the month of April
print(a.is_month_end)
print(b.is_month_end)

Explanation

  • Line 3: We import the pandas library.
  • Line 6 and 7: We create time stamp objects, a and b.
  • Line 10 and 11: We obtain and print to console, the result indicating which of a and b is the last day of the month using the is_month_end attribute.

Free Resources