![]() |
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. Example 1: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. Python3
Output: ![]() Output Example 2:In this example, we give the string “M” as the frequency which gives us a period index object of type “MonthEnd”. we also specify the time stamp object to have a frequency of “M”. Python3
Output: ![]() Output Example 3: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”. Python3
Output: ![]() Output |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |