Python Pandas Period.freqstr Attribute:
The string alias of the Time series frequency applied to the specified Period object is returned by the Period.freqstr attribute of Pandas module.
Syntax:
Period.freqstr
Parameters: It has no arguments
Return Value:
The Period.freqstr attribute of Pandas module returns a string.
Pandas Period.freqstr Attribute in Python
Example1
Here, the returned ‘D’ in the output, represents that the time series frequency applied to the specified object was a day.
Approach:
- Import pandas module using the import keyword.
- Pass freq =’D'(here D represents Day), some random year, month, day, as the arguments to the Period() function of the pandas module to get the period object
- Print the above obtained period object
- Apply freqstr attribute to the above period object to get a string alias of the Time series frequency applied to the given Period object.
-
The Exit of the Program.
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Pass freq ='D'(here D represents Date), some random year, month, day, # as the arguments to the Period() function of the # pandas module to get the period object period_obj = pd.Period(freq ='D', year = 2021, month = 8, day = 15) # Print the above obtained period object print("The above obtained period object:", period_obj) # Apply freqstr attribute to the above period object to get a # string alias of the Time series frequency applied to the given Period object print("String alias of the Time series frequency applied to the given Period object:") period_obj.freqstr
Output:
The above obtained period object: 2021-08-15 String alias of the Time series frequency applied to the given Period object: 'D'
Example2
Here, the returned ‘Q-DEC’ in the output, represents that the time series frequency applied to the specified period object is the end of the quarter of the year
Approach:
- Import pandas module using the import keyword.
- Pass freq =’Q’, some random year, quarter as the arguments to the Period() function of the pandas module to get the period object.
- Print the above obtained period object
- Apply freqstr attribute to the above period object to get a string alias of the Time series frequency applied to the given Period object.
-
The Exit of the Program.
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Pass freq ='Q', some random year, quarter # as the arguments to the Period() function of the # pandas module to get the period object period_obj = pd.Period(freq ='Q', year = 2021, quarter = 1) # Print the above obtained period object print("The above obtained period object:", period_obj) # Apply freqstr attribute to the above period object to get a # string alias of the Time series frequency applied to the given Period object print("String alias of the Time series frequency applied to the given Period object:") period_obj.freqstr
Output:
The above obtained period object: 2021Q1 String alias of the Time series frequency applied to the given Period object: 'Q-DEC'