In this article, we will discuss how to convert period index objects to timestamp and set the frequency in the python programming language.
The pandas PeriodIndex.to_timestamp() method is used to convert a PeriodIndex object to Timestamp and set the frequency. frequency can be set using the ‘freq’ parameter of the method.
Pandas package is imported. A period index object is created using pd.PeriodIndex() function where we pass in an array of DateTime values and frequency is specified as “year”. The period index object will have YearEnd type frequency. PeriodIndex object is converted to timestamp object by using the pd.to_timestamp() method.
In this example, we give the string “D” as the frequency which gives us a period index object of type “Day”. we also specify the time stamp object to have a frequency of “D”. The period Index object values match exactly with the values in the Timestamp object as we specify frequency to be “Day”.
Please Login to comment...