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 library
import pandas as pd
# Creating a period object
a = pd.Period('2022-5-2')
b = pd.Period('2020-5-2')
# Checking if the period's year is a leap year or not
print(a.is_leap_year)
print(b.is_leap_year)

Explanation

  • Line 3: We import the pandas library.
  • Lines 6–7: We create Period objects a and b with different year component values.
  • Lines 10–11: We check to see if a or b have values of leap years.
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources