Python | Pandas PeriodIndex.qyear

Python | Pandas PeriodIndex.qyear

The qyear attribute of a PeriodIndex object in pandas returns the year of the respective quarters present in the PeriodIndex.

A PeriodIndex is used to represent a time span or a period, like a specific day or month or quarter.

Here's an example of how you can use the qyear attribute with a PeriodIndex:

import pandas as pd # Create a PeriodIndex with quarterly frequency idx = pd.PeriodIndex(['2021Q1', '2021Q2', '2021Q3', '2022Q1'], freq='Q') # Access the year of each quarter using the qyear attribute print(idx.qyear) 

Output:

Int64Index([2021, 2021, 2021, 2022], dtype='int64') 

In the example, we created a PeriodIndex with quarterly periods. Using the qyear attribute, we can access the year of each quarter in the PeriodIndex.


More Tags

guava gpo button tabletools macos slack-api gunicorn durandal avaudioplayer zone.js

More Programming Guides

Other Guides

More Programming Examples