+

Python | Pandas DatetimeIndex.quarter

DatetimeIndex.quarter Pandas DatetimeIndex.quarter displays a quarter date for each record in a DatetimeIndex object.

Syntax: DatetimeIndex.quarter

Return: Index object

Example # 1: Use the DatetimeIndex.quarter attribute to find the quarter date for each record in the DatetimeIndex object.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here “M »Represents the monthly frequency

didx = pd .DatetimeIndex (s tart = `2014-08-01 10:05:45` , freq = `M`

periods = 5 , tz = `Asia / Calcutta` )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to find the quarter date for each entry in the DatetimeIndex object.

< tr>

# find the quarter of the date
didx.quarter

Output:

As we can see in the output, the function returned an Index object containing a quarter date value for each entry in the DatetimeIndex object.

Example # 2: Use the DatetimeIndex.quarter attribute to find the quarter date for each record in the DatetimeIndex object.

Output:

Now we want to find the quarter date for each entry in a DatetimeIndex object.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here “Q "Represents the quarterly frequency

didx = pd.DatetimeIndex (start = `2000-01-10 06:30` , freq = `Q` ,

periods = 5 , tz = `Asia / Calcutta` )

  
# Print DatetimeIndex

print (didx)

# find the quarter of the date
didx.quarter

Output:

As we can see in the output, the function returned an Index object containing a quarter date value for each entry in the DatetimeIndex object.

Get Solution for free from DataCamp guru