Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python DataFrame.resample()已关闭,未按预期运行_Python_Pandas - Fatal编程技术网

Python DataFrame.resample()已关闭,未按预期运行

Python DataFrame.resample()已关闭,未按预期运行,python,pandas,Python,Pandas,首先,让我们为每分钟的数据创建一个样本: >>> index = pd.date_range('1/1/2000', periods=60*24*400, freq='T') >>> series = pd.Series(range(60*24*400), index=index) >>> series.head() 2000-01-01 00:00:00 0 2000-01-01 00:01:00 1 2000-01-01 00

首先,让我们为每分钟的数据创建一个样本:

>>> index = pd.date_range('1/1/2000', periods=60*24*400, freq='T')
>>> series = pd.Series(range(60*24*400), index=index)
>>> series.head()
2000-01-01 00:00:00    0
2000-01-01 00:01:00    1
2000-01-01 00:02:00    2
2000-01-01 00:03:00    3
2000-01-01 00:04:00    4
当重新采样到每日频率时,我可以看到
关闭的影响:

>>> series.resample('D', closed="right").head()
1999-12-31       0.0  # <-- here, I get some data labeled 1999
2000-01-01     720.5
2000-01-02    2160.5
2000-01-03    3600.5
2000-01-04    5040.5
Freq: D, dtype: float64
>>> series.resample('D', closed="left").head()
2000-01-01     719.5
2000-01-02    2159.5
2000-01-03    3599.5
2000-01-04    5039.5
2000-01-05    6479.5
>>> series.resample('M', closed="right").head()
2000-01-31     22319.5  # <-- ?
2000-02-29     65519.5
2000-03-31    108719.5
2000-04-30    152639.5
2000-05-31    196559.5
Freq: M, dtype: float64
>>> series.resample('M', closed="left").head()
2000-01-31     21599.5
2000-02-29     64079.5
2000-03-31    107279.5
2000-04-30    151199.5
2000-05-31    195119.5
Freq: M, dtype: float64

这一定是由于label属性造成的。您链接的文档将其描述为

标签:{'right','left'} 使用哪个箱子边缘标签来标记桶。除“M”、“A”、“Q”、“BM”、“BA”、“BQ”和“W”之外的所有频率偏移的默认值均为“左”,这些频率偏移的默认值均为“右”

试着做:

series.resample('D', closed="right", label="right").head()

您会看到月份和日期的不同行为,因为默认标签是D的“左”和M的“右”。哦,对了。我猜您的意思是
系列。重新采样('M',closed=“right”,label=“left”)。head()
。但是是的,您是对的。
series.resample('D', closed="right", label="right").head()