'How to get strftime to output yearly quarters?

I am trying to create a list of year-quarters in python; per the documentation (https://pandas.pydata.org/docs/reference/api/pandas.Period.strftime.html), %q (I believe) should output an integer representation of calendar quarter, but instead the output I get is just %q literally.

Input:

pd.date_range('2021-01-01','2022-01-01',freq='Q').strftime('%Y-%q').tolist()

Expected Output:

['2021-01', '2021-02', '2021-03', '2021-04']

Actual Output:

['2021-%q', '2021-%q', '2021-%q', '2021-%q']


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source