Python | Pandas Timestamp.is_month_end

Python Methods and Functions

The Pandas Timestamp.is_month_end attribute returns a boolean value. It returns True if the date in the given Timestamp object is the last day of the month, otherwise it returns False .

Syntax: Timestamp.is_month_end

Parameters: None

Return: boolean

Example # 1: Use the Timestamp.is_month_end attribute to check if the date in this Timestamp object is the last day of the month.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp ( 2016 ,   2 , 14 , 12 )

 
# Print the Timestamp object

print (ts)

Output:

We will now use the Timestamp.is_month_end attribute to check if whether the date in the ts object is the last day of the month or not.

# check if the date in the vehicle is the last day of the month
ts.is_month_end

Output:

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

Example # 2: Use the Timestamp.is_month_end attribute to check if whether the date in this Timestamp object is the last day of the month.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2009 , month < code class = "keyword"> = 5 , day = 31

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

 
# Print Timestamp object

print (ts)

Output:

Now we will use the Timestamp.is_month_end attribute to check if the date in the ts object is the last day of the month or not.

# check if the date in the vehicle is the last day of the month
ts.is_month_end

Output:

Like us as seen from the output, the Timestamp.is_month_end attribute returned True indicating that the date in this Timestamp object is the last day of the month.





Get Solution for free from DataCamp guru