Python Pandas Period.end_time Attribute

Pandas Period.end_time Attribute:

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

Syntax:

Period.end_time

Parameters: It has no arguments

Return Value:

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

Pandas Period.end_time Attribute in Python

Example1

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

Approach:

  • Import pandas module using the import keyword.
  • Pass some random frequency(here D= Day frequency), year, month, day, as the arguments to the Period() function of the pandas module to get the Period object.
  • Print the given period object.
  • Apply end_time() attribute on the above period object to get the end 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 D= Day frequency), 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 = 2015, month = 5, day = 16)                        
# Print the given period object
print("The given period object:")
print(period_obj)
print()

# Apply end_time() attribute on the above period object to get the 
# end time of the given period object.
print("The end time of the given period object:")
period_obj.end_time

Output:

The given period object:
2015-05-16

The end time of the given period object:
Timestamp('2015-05-16 23:59:59.999999999')

Example2

We can also pass freq = H( hourly frequency), T(minutely), S(secondly), D(Day), Q(quaterly) etc.

Approach:

  • Import pandas module using the import keyword.
  • Pass some random frequency(here Q= Quaterly frequency), year, quarter as the arguments to the Period() function of the pandas module to get the Period object
  • Print the given period object.
  • Apply end_time() attribute on the above period object to get the end 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 Q= Quaterly frequency), 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= 2)                        
# Print the given period object
print("The given period object:")
print(period_obj)
print()

# Apply end_time() attribute on the above period object to get the 
# end time of the given period object.
print("The end time of the given period object:")
period_obj.end_time

Output:

The given period object:
2021Q2

The end time of the given period object:
Timestamp('2021-06-30 23:59:59.999999999')

Leave a Comment