207

所以我完全理解如何使用resample,但是文档并没有很好地解释这些选项。

所以resample函数中的大多数选项都非常简单,除了这两个:

  • rule : 表示目标转换的偏移量字符串或对象
  • how : 字符串,下采样或重采样的方法,默认为 'mean'</li>

因此,通过查看我在网上找到的尽可能多的示例,我可以看到您可以'D'在一天、'xMin'几分钟、'xL'几毫秒内执行的规则,但这就是我能找到的全部。

对于我如何看到以下内容:'first', np.max, 'last', 'mean','n1n2n3n4...nx'其中 nx 是每个列索引的第一个字母。

那么文档中是否有我遗漏的地方显示了pandas.resample规则的每个选项以及如何输入?如果是,在哪里,因为我找不到它。如果没有,他们的所有选择是什么?

4

2 回答 2

356
B         business day frequency
C         custom business day frequency (experimental)
D         calendar day frequency
W         weekly frequency
M         month end frequency
SM        semi-month end frequency (15th and end of month)
BM        business month end frequency
CBM       custom business month end frequency
MS        month start frequency
SMS       semi-month start frequency (1st and 15th)
BMS       business month start frequency
CBMS      custom business month start frequency
Q         quarter end frequency
BQ        business quarter endfrequency
QS        quarter start frequency
BQS       business quarter start frequency
A         year end frequency
BA, BY    business year end frequency
AS, YS    year start frequency
BAS, BYS  business year start frequency
BH        business hour frequency
H         hourly frequency
T, min    minutely frequency
S         secondly frequency
L, ms     milliseconds
U, us     microseconds
N         nanoseconds

请参阅时间序列文档。它包括一个偏移列表(和“锚定”偏移),以及一个关于重采样的部分。

请注意,没有所有不同how选项的列表,因为它可以是任何 NumPy 数组函数,并且任何通过groupby 调度可用的函数都可以按名称传递how

于 2013-06-08T16:20:07.050 回答
66

不止于此,您可能正在寻找此列表:

B   business day frequency
C   custom business day frequency (experimental)
D   calendar day frequency
W   weekly frequency
M   month end frequency
BM  business month end frequency
MS  month start frequency
BMS business month start frequency
Q   quarter end frequency
BQ  business quarter endfrequency
QS  quarter start frequency
BQS business quarter start frequency
A   year end frequency
BA  business year end frequency
AS  year start frequency
BAS business year start frequency
H   hourly frequency
T   minutely frequency
S   secondly frequency
L   milliseconds
U   microseconds

Source: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases

于 2013-11-06T19:43:41.670 回答