Python | Pandas DatetimeIndex.is_year_end

NumPy | Python Methods and Functions

DatetimeIndex.is_year_end Pandas DatetimeIndex.is_year_end is an indicator of whether a date is the last day of the year. If the date is the last day of the year it returns True otherwise it returns False .

Syntax: DatetimeIndex. is_year_end

Returns: numpy array containing logical values.

Example # 1: Use the attribute DatetimeIndex.is_year_end to check if the dates in the DatetimeIndex are the last day of the year.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex

didx = pd.DatetimeIndex ([ `2014-01-01` , `2014- 12-31` , `2017-03-31` , `2000-12-31` ])

  
# Print DatetimeIndex

print (didx)

Output:

Now we want to find out if the dates contained in this DatetimeIndex object are last day of the year.

# determine if days are the last day of the year.
didx. is_year_end

Exit:

As we can see in the output, the function returned an empty array containing boolean values ​​for each entry in the DatetimeIndex object.  True values ​​indicate that the corresponding date was the last day of the year, and False values ​​indicate that the corresponding date was not the last day of the year.

Example # 2: Use the DatetimeIndex.is_year_end attribute to check if the dates in the DatetimeIndex are the last day of the year.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex

didx = pd.date_range ( "2017-12-30" , periods = 5 )

  
# Print DatetimeIndex

print (didx)

Output:

Now we want to find out if the dates contained in this DatetimeIndex object, the last day of the year.

# determine if days are the last day of the year.
didx.is_year_end

Output:

As we can see in the output, the function returned an empty array containing boolean values ​​for each object record DatetimeIndex.  True values ​​indicate that the corresponding date was the last day of the year, and False values ​​indicate that the corresponding date was not the last day of the year.





Get Solution for free from DataCamp guru