Python Pandas Period.start_time Attribute

Pandas Period.start_time Attribute:

The Period.start_time attribute of the Pandas module gives a Timestamp object that contains the start time of the specified period object.

Syntax:

Period.start_time

Parameters: It has no arguments

Return Value:

The Timestamp object which contains the start time of the specified period object is returned by the Period.start_time attribute.

Pandas Period.start_time Attribute in Python

Example1

Here, the Period.start_time attribute gives a Timestamp object containing both the date value and the start time of the given period object.

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 start_time() attribute on the above period object to get the start time of 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 start_time() attribute on the above period object to get the 
# start time of the given period object.
print("The start time of the given period object:")
period_obj.start_time

Output:

The given period object:
2021-03-15 05:25:16

The start time of the given period object:
Timestamp('2021-03-15 05:25:16')

Example2

We can also pass freq = H( hourly frequency), T, S, etc.

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 start_time() attribute on the above period object to get the start time of 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 start_time() attribute on the above period object to get the 
# start time of the given period object.
print("The start time of the given period object:")
period_obj.start_time

Output:

The given period object:
2015-05-16 12:28:10

The start time of the given period object:
Timestamp('2015-05-16 12:28:10')