Python Pandas - Find the end time for the given Period object

To find the end time for the given Period object, use the period.end_time property. This property returns a Timestamp representing the end time of the period.

Syntax

period.end_time

Returns: Timestamp representing the end time of the period

Creating Period Objects

First, let's import pandas and create Period objects with different frequencies ?

import pandas as pd

# Create Period objects with different frequencies
period1 = pd.Period("2020-09-23 03:55:20")
period2 = pd.Period(freq="T", year=2021, month=2, day=14, hour=2, minute=35)

print("Period1:", period1)
print("Period2:", period2)
Period1: 2020-09-23 03:55:20
Period2: 2021-02-14 02:35

Getting End Time Using end_time Property

The end_time property returns the last possible timestamp within the period ?

import pandas as pd

# Create Period objects
period1 = pd.Period("2020-09-23 03:55:20")
period2 = pd.Period(freq="T", year=2021, month=2, day=14, hour=2, minute=35)

# Get end time from Period objects
end_time1 = period1.end_time
end_time2 = period2.end_time

print("End time of period1:", end_time1)
print("End time of period2:", end_time2)
End time of period1: 2020-09-23 03:55:20.999999999
End time of period2: 2021-02-14 02:35:59.999999999

Different Frequency Examples

Let's see how end_time works with different period frequencies ?

import pandas as pd

# Create periods with different frequencies
daily_period = pd.Period("2023-05-15", freq="D")
monthly_period = pd.Period("2023-05", freq="M")
yearly_period = pd.Period("2023", freq="Y")

print("Daily period end time:", daily_period.end_time)
print("Monthly period end time:", monthly_period.end_time)
print("Yearly period end time:", yearly_period.end_time)
Daily period end time: 2023-05-15 23:59:59.999999999
Monthly period end time: 2023-05-31 23:59:59.999999999
Yearly period end time: 2023-12-31 23:59:59.999999999

Key Points

  • The end_time property returns a Timestamp object
  • It represents the last possible moment within the period
  • For second-level periods, it adds nanoseconds to reach the end
  • Different frequencies result in different end times

Conclusion

The end_time property is useful for getting the precise end timestamp of any Period object. It automatically adjusts based on the period's frequency, making it perfect for time-based calculations and period boundary analysis.

Updated on: 2026-03-26T16:27:43+05:30

251 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements