Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
data science
communitycreator

How to check if the date is the last day of the year in Pandas

Onyejiaku Theophilus Chidalu

Overview

The is_year_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 year.

Syntax

The is_year_end attribute takes the syntax below:

Timestamp.is_year_end
Syntax for the is_year_end attribute

Parameter

The attribute takes no parameter values.

Return value

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

Example

Let's look at the code below:

# A code to illustrate the .is_year_end attribute in Pandas
# importing the pandas library
import pandas as pd

# creating a Timestamp object
a = pd.Timestamp(2022, 12, 30)
b = pd.Timestamp(2022, 12, 31)

# checking if date is the last day of the year
print(a.is_year_end)
print(b.is_year_end)
Implementing the is_year_end attribute

Explanation

  • Line 3: We import the pandas library.
  • Lines 6 and 7: We create Timestamp objects, a and b, representing the month of December.
  • Line 10: We use the is_year_end to indicate if any of the dates are the year's last day.

RELATED TAGS

pandas
data science
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring