Pandas

Pandas中resample方法怎么使用

小亿
206
2023-08-12 03:44:37
栏目: 编程语言
开发者专用服务器限时活动,0元免费领! 查看>>

在Pandas中,resample方法用于重新采样时间序列数据。

使用resample方法的一般语法如下:

df.resample(rule, how, axis, fill_method, closed, label)

其中,常用参数的含义如下:

下面是一个使用resample方法重新采样时间序列数据的示例:

import pandas as pd
# 创建一个时间序列数据
data = pd.Series([1, 2, 3, 4, 5], index=pd.date_range('2021-01-01', periods=5, freq='D'))
# 按周重新采样,求和
resampled_data = data.resample('W').sum()
print(resampled_data)

输出结果为:

2021-01-03    6
2021-01-10    9
Freq: W-SUN, dtype: int64

在上述示例中,我们创建了一个包含5个元素的时间序列数据data,并将其按周重新采样,并求和得到resampled_data。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:Pandas中resample方法详解

0
看了该问题的人还看了