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