0

How would generate in the most concise way a monthly period index that is observed only every 12 months?

I came up with the following solution

pd.period_range(start=pd.Period('1975-07'), 
                end=pd.Period('1985-07'),
                freq='M'
                ).to_frame().iloc[::12].index

but I was wondering if there is a way that avoids the conversion from period index to dataframe and back to period index.

This is the expected output:

PeriodIndex(['1975-07', '1976-07', '1977-07', '1978-07', '1979-07', '1980-07',
             '1981-07', '1982-07', '1983-07', '1984-07', '1985-07'],
            dtype='period[M]', freq='M')
user64150
  • 59
  • 5

1 Answers1

1

Use freq='12M':

pd.period_range(start=pd.Period('1975-07'), 
                end=pd.Period('1985-07'),
                freq='12M'
                )
Code Different
  • 90,614
  • 16
  • 144
  • 163