Để tìm thời gian kết thúc (end time) của đối tượng Period, sử dụng thuộc tính period.end_time. Trả về Timestamp đại diện cho thời điểm cuối cùng của khoảng thời gian đó.
Các bước thực hiện
- Import thư viện:
import pandas as pd - Tạo hai Period object:
period1 = pd.Period("2020-09-23 03:55:20")(tần suất giây)period2 = pd.Period(freq="T", year=2021, month=2, day=14, hour=2, minute=35)(tần suất phút)
- Truy cập
period1.end_timevàperiod2.end_time.
Ví dụ hoàn chỉnh
import pandas as pd
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...\n", period1)
print("Period2...\n", period2)
res1 = period1.end_time
res2 = period2.end_time
print("\nDisplay the end time from the 1st Period object ...\n", res1)
print("\nDisplay the end time from the 2nd Period object ...\n", res2)
Kết quả
Period1... 2020-09-23 03:55:20
Period2... 2021-02-14 02:35
Display the end time from the 1st Period object ... 2020-09-23 03:55:20.999999999
Display the end time from the 2nd Period object ... 2021-02-14 02:35:59.999999999
Giải thích: end_time trả về Timestamp kết thúc của khoảng thời gian Period (ví dụ: Period 1 giây kết thúc ở nanosecond cuối cùng của giây đó).