+

Python | Pandas Timestamp.is_year_end

The Pandas attribute Timestamp.is_year_end returns a boolean value. It returns True if the date in the given Timestamp object is the end of the year, otherwise it returns False .

Syntax: Timestamp.is_year_end

Parameters: None

Return: boolean

Example # 1: Use the Timestamp.is_year_end attribute to check if the date in a given Timestamp object is the end of the year or not.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp ( 2016 , 12 , 31 , 12 )

 
# Print the Timestamp object

print (ts)

Output:

Now we will use the Timestamp.is_year_end attribute to check if the date is in the ts object end of year or not.

# check if the date is the end of the year
ts.is_year_end

Output:

As we can see in the output, the Timestamp.is_year_end attribute returned True with the date in the given year-end Timestamp object .

Example # 2: Use the Timestamp.is_year_end attribute to check if the date in a given Timestamp object is the end of the year or not.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2009 , month = 5 , day = 31

hour = 4 , tz = ` Europe / Berlin` )

 
# Print the Timestamp object

print (ts)

Output:

We will now use the Timestamp.is_year_end attribute to check if the date in the ts object is the end of the year or not.

# check if the date is the end of the year
ts.is_year_end

Output:

As we can see from the output, the Timestamp.is_year_end attribute returned False indicating that the date in this Timestamp object is not end of the year.

Get Solution for free from DataCamp guru