Python Pandas - 顯示給定 PeriodIndex 物件中每個元素的週期結束時間
要顯示給定 PeriodIndex 物件中每個元素的週期結束時間,請使用 **PeriodIndex.end_time** 屬性。
首先,匯入必需的庫 −
import pandas as pd
建立一個 PeriodIndex 物件。PeriodIndex 是一個不可變的 ndarray,其中包含表示時間中規律週期的序數值。我們已使用 "freq" 引數設定了頻率 −
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], freq="D")
顯示 PeriodIndex 物件 −
print("PeriodIndex...\n", periodIndex)顯示結束時間 −
print("\nEnd Time...\n", periodIndex.end_time)示例
以下為程式碼 −
import pandas as pd
# Create a PeriodIndex object
# PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time
# We have set the frequency using the "freq" parameter
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20',
'2021-09-15', '2022-03-12', '2023-06-18'], freq="D")
# Display PeriodIndex object
print("PeriodIndex...\n", periodIndex)
# Display PeriodIndex frequency
print("\nPeriodIndex frequency...\n", periodIndex.freq)
# Display the end time
print("\nEnd Time...\n", periodIndex.end_time)輸出
這將生成以下程式碼 −
PeriodIndex... PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], dtype='period[D]') PeriodIndex frequency... <Day> End Time... DatetimeIndex(['2018-07-25 23:59:59.999999999', '2019-10-30 23:59:59.999999999', '2020-11-20 23:59:59.999999999', '2021-09-15 23:59:59.999999999', '2022-03-12 23:59:59.999999999', '2023-06-18 23:59:59.999999999'], dtype='datetime64[ns]', freq=None)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP