Python | Pandas DatetimeIndex.is_year_start

NumPy | Python Methods and Functions

DatetimeIndex.is_year_start Pandas DatetimeIndex.is_year_start is an indicator of whether a date is the first day of the year. If the date — the first day of the year, it returns True otherwise it returns False .

Syntax: DatetimeIndex.is_year_start

Return: numpy array containing logical values.

Example # 1: Use the DatetimeIndex.is_year_start to check if the dates in the DatetimeIndex are the first day of the year.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex

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

 
# Print DatetimeIndex

print (didx)

Output:

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

# determine if these days are the first day of the year.
didx.is_year_start

Output:

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 first day of the year, and False values ​​indicate that the corresponding date was not the first day of the year.

Example # 2: Use the DatetimeIndex.is_year_start attribute to check if the dates present in the DatetimeIndex object are the first day of the year.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex

didx = pd.date_range ( ` 2011-12-30 ` , periods = 5 )

< code class = "undefined spaces">  
# Print DatetimeIndex

print (didx)

Output:

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

# determine if these days are the first day of the year.
didx.is_year_start

Exit :

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





Get Solution for free from DataCamp guru