- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Check whether the year is a leap year from the Period object
To check whether the year is a leap year from the Period object, use the period.is_leap_year property. At first, import the required libraries −
import pandas as pd
The pandas.Period represents a period of time. Creating two Period objects
period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="Y", year = 2021, month = 7, day = 16, hour = 2, minute = 35)
Display the Period objects
print("Period1...\n", period1) print("Period2...\n", period2)
Check whether the year is a leap year
res1 = period1.is_leap_year res2 = period2.is_leap_year
Example
Following is the code
import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="Y", year = 2021, month = 7, day = 16, hour = 2, minute = 35) # display the Period objects print("Period1...\n", period1) print("Period2...\n", period2) # Check whether the year is a leap year res1 = period1.is_leap_year res2 = period2.is_leap_year # Returns True of the year is a leap year, else False print("\nIs the year in the 1st Period object a leap year ...\n", res1) print("\nIs ths year in the 2nd Period object a leap year ...\n", res2)
Output
This will produce the following code
Period1... 2020-09-23 05:55:30 Period2... 2021 Is the year in the 1st Period object a leap year ... True Is ths year in the 2nd Period object a leap year ... False
- Related Articles
- Python Pandas - Get the year from the Period object
- Golang Program to Check Whether a Given Year is a Leap Year
- Python Pandas - Get the Day of the year from Period object
- Python Pandas - Get the quarter of the year from Period object
- Python Pandas - Indicate if the date from the PeriodIndex object belongs to a leap year
- Check if a given year is leap year in PL/SQL
- JavaScript program to check if a given year is leap year
- Python Pandas - Indicate whether the date in DateTimeIndex belongs to a leap year or not
- Python Pandas - Format the Period object and display the Year without century
- How to Check Leap Year using Python?
- Python Pandas - Get the year from the PeriodIndex object
- How to check whether a year or a vector of years is leap year or not in R?
- Program to check if a given year is leap year in C
- PHP program to check if a year is leap year or not
- C++ Program to Check Leap Year

Advertisements