Pandas Period.second Attribute:
The Period.second attribute of the Pandas module gives an integer value that indicates the number of seconds in the specified Period object.
Syntax:
Period.second
Parameters: It has no arguments
Return Value:
The seconds value in the specified Period object is returned by the Period.second attribute of the Pandas module.
- Python Pandas Period.dayofyear Attribute
- Python Pandas Period.week Attribute
- Python Pandas Period.start_time Attribute
Pandas Period.second Attribute in Python
Example1
Here, the Period.second attribute returns 16, representing that the number of seconds in the given period object is 16.
Approach:
- Import pandas module using the import keyword.
- Pass some random frequency(here S= secondly frequency), year, month, day, hour, minute, second as the arguments to the Period() function of the pandas module to get the Period object
- Print the given period object
- Apply the second() attribute on the above period object to get the seconds value in 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 some random frequency(here S= secondly frequency), year, month, day, # hour, minute, second as the arguments to the Period() function # of the pandas module to get the Period object period_obj = pd.Period(freq ='S', year = 2021, month = 3, day = 15, hour = 5, minute = 25, second = 16) # Print the given period object print("The given period object:") print(period_obj) print() # Apply second() attribute on the above period object to get the # seconds value in the given period object. print("The seconds value in the given period object:") period_obj.second
Output:
The given period object: 2021-03-15 05:25:16 The seconds value in the given period object: 16
Example2
Here, the Period.second attribute returns 10, representing that the number of seconds in the given period object is 10.
Approach:
- Import pandas module using the import keyword.
- Pass some random frequency(here S= secondly frequency), year, month, day, hour, minute, second as the arguments to the Period() function of the pandas module to get the Period object
- Print the given period object
- Apply the second() attribute on the above period object to get the seconds value in 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 some random frequency(here S= secondly frequency), year, month, day, # hour, minute, second as the arguments to the Period() function # of the pandas module to get the Period object period_obj = pd.Period(freq ='S', year = 2015, month = 5, day = 16, hour = 12, minute = 28, second = 10) # Print the given period object print("The given period object:") print(period_obj) print() # Apply second() attribute on the above period object to get the # seconds value in the given period object. print("The seconds value in the given period object:") period_obj.second
Output:
The given period object: 2015-05-16 12:28:10 The seconds value in the given period object: 10