DataFrame.resample(freq)
2020-08-04 本文已影响0人
喝奶茶不加奶茶
DataFrame.resample(freq),将数据基于时间列以 freq 作为频度对全局数据做重采样,计算出分段数据和、均值、方差等指标;下面例子中原数据的索引是 Datatime 数据格式,以月为时间单位求出各列数据的平均值。
# Resample the data based the offset,get the mean of data
# BM — bussiness month end frequency
apple_month = apple.resample("BM").mean()
apple_month.head()
M 全称 Bussiness Month,是商业月的意思,在 Pandas 中称为 DataOffset,除了月之外,还提供年、日、秒、小时、分…等作为采样单位,当然也可以自定义。