【问题标题】:pandas resample documentation熊猫重采样文档
【发布时间】:2013-06-04 18:44:52
【问题描述】:

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

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

  • 规则:表示目标转换的偏移量字符串或对象
  • how : 字符串,下采样或重采样的方法,默认为“mean”

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

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

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

【问题讨论】:

  • 对于谷歌的流浪者,使用how='last'how='first'重新采样:不要忘记添加closed='left', label='left'link
  • @NasserAl-Wohaibi 我相当有信心您的上述评论表明这些选项可以帮助完全回答以下问题。你以前遇到过这个问题吗? stackoverflow.com/questions/26247301/…
  • how='last' 现在已弃用,取而代之的是 resample(...).last()

标签: python documentation pandas


【解决方案1】:
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

请参阅timeseries documentation。它包括offsets(和'anchored' offsets)的列表,以及关于resampling 的部分。

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

【讨论】:

  • " ...因为它可以是任何 NumPy 数组函数,并且..." - 是的,我在文档中读到了,但是有任何文档解释这个函数到底应该做什么它与重采样有什么关系......?我在这里感觉很迷茫。
  • 这应该链接到所有相关文档区域,例如重新采样。这是缩写的链接:pandas.pydata.org/pandas-docs/stable/…
  • 添加了一个拉取请求以改进文档github.com/pandas-dev/pandas/pull/30252
【解决方案2】:

除此之外还有更多内容,但您可能正在寻找此列表:

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

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

【讨论】:

  • 为什么没有“Min”(如文档中使用的“5Min”)?
  • @zyuang,这里只显示短格式:例如列表中也没有“ms”
猜你喜欢
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 2015-11-21
  • 2017-10-09
  • 2022-06-10
  • 2017-02-20
相关资源
最近更新 更多