What is the Period.is_leap_year attribute in pandas?
Overview
The is_leap_year attribute of a Period object in Pandas checks whether the date of the Period is a leap year.
Syntax
The is_leap_year attribute takes the syntax below:
Period.is_leap_year
Syntax for the is_leap_year attribute
Parameter value
The is_leap_year attribute takes no parameter value.
Return value
The is_leap_year attribute returns a boolean value: True if the year specified in the Period object is a leap year, and False otherwise.
Example
# A code to illustrate the is_leap_year attribute# Importing the Pandas libraryimport pandas as pd# Creating a period objecta = pd.Period('2022-5-2')b = pd.Period('2020-5-2')# Checking if the period's year is a leap year or notprint(a.is_leap_year)print(b.is_leap_year)
Explanation
- Line 3: We import the
pandaslibrary. - Lines 6–7: We create
Periodobjectsaandbwith different year component values. - Lines 10–11: We check to see if
aorbhave values of leap years.