1

I would like to convert an object from pandas.core.indexes.accessors.PeriodProperties to a Datetime variable.

As an example, I want to convert a period variable (not a string) with the format "2019Q1" to a datetime format, "2019-03-31".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Crypt_Fomo
  • 11
  • 2

1 Answers1

0

Assuming you have something like pi as in

pi = pd.PeriodIndex(["2019Q1", "2019Q2"], freq='Q')

then you want

pi.to_timestamp() + pd.offsets.QuarterEnd(0)

Out[11]: DatetimeIndex(['2019-03-31', '2019-06-30'], dtype='datetime64[ns]', freq=None)

It is basically described here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
FObersteiner
  • 22,500
  • 8
  • 42
  • 72