To change the frequency of the given Period object from Seconds to Minutely frequency, use the period.asfreq() method and set the parameter ‘T’.
At first, import the required libraries −
import pandas as pd
The pandas.Period represents a period of time. Creating a Period object. We have set the frequency as seconds i.e. 'S' using the 'freq' parameter
period = pd.Period(freq="S", year = 2021, month = 9, day = 11, hour = 8, minute = 20, second = 45)
Display the Period object with Seconds frequency
print("Period...\n", period)
Convert Period from Seconds to Minutely frequency. We have set the "T" to convert seconds to minutely frequency using asfreq()
res = period.asfreq('T')
Example
Following is the code
import pandas as pd # The pandas.Period represents a period of time # Creating a Period object # We have set the frequency as seconds ie. 'S' using the 'freq' parameter period = pd.Period(freq="S", year = 2021, month = 9, day = 11, hour = 8, minute = 20, second = 45) # display the Period object with Seconds frequency print("Period...\n", period) # Convert Period from Seconds to Minutely frequency # We have set the "T" to convert seconds to minutely frequency using asfreq() res = period.asfreq('T') # display the result after conversion from Seconds to Minutely frequency print("\nFinal result after converting frequency ...\n", res)
Output
This will produce the following code
Period... 2021-09-11 08:20:45 Final result after converting frequency ... 2021-09-11 08:20