Python Pandas - 创建一个 PeriodIndex 并设置频率
要创建PeriodIndex,请使用方法。要设置频率,请使用freq参数。pandas.PeriodIndex()
首先,导入所需的库-
import pandas as pd
创建一个PeriodIndex对象。PeriodIndex是一个不可变的ndarray,其中包含指示定期时间段的序数值。我们使用“freq”参数设置了频率-
periodIndex = pd.PeriodIndex(['2021-09-25', '2020-10-30', '2020-11-20'], freq="D")
显示PeriodIndex对象-
print("PeriodIndex...\n", periodIndex)示例
以下是代码-
import pandas as pd
#创建一个PeriodIndex对象
#PeriodIndex是一个不可变的ndarray,其中包含指示定期时间段的序数值
# We have set the frequency using the "freq" parameter
periodIndex = pd.PeriodIndex(['2021-09-25', '2020-10-30', '2020-11-20'], freq="D")
#显示PeriodIndex对象
print("PeriodIndex...\n", periodIndex)
#显示来自PeriodIndex对象的日期
print("\nThe number of days from the PeriodIndex...\n", periodIndex.day)输出结果这将产生以下代码-
PeriodIndex... PeriodIndex(['2021-09-25', '2020-10-30', '2020-11-20'], dtype='period[D]') The number of days from the PeriodIndex... Int64Index([25, 30, 20], dtype='int64')
热门推荐
3 初八祝福语简短语
10 周末祝福语简短的英语
11 新年给妹妹祝福语简短
12 婚礼祝福语简短情话短句
13 怎么说祝福语简短
14 家长祝福语大全简短内容
15 新娘上头祝福语大全简短
16 生病祝福语简短文案
17 对生活祝福语简短精辟
18 商业mc祝福语大全简短