尝试使用Panda的.resample()函数从不规则的观察中进行上采样(例如,从大约7秒到小时样本,使用最后一次观察) . 我一直收到此错误消息:

AttributeError: type object 'Grouper' has no attribute '_attributes'

即使使用先前提出的问题的语法(Pandas resample和其他人) . Pandas一般可以使用不规则的Datetime索引(来自Cookbook)

我的问题似乎是DataFrame I 'm trying to apply .resample() to, but I can'的数据格式,弄清楚它有什么问题 . Pandas版本是0.21.0(来自conda,64位linux,Python 3.6.4) .

在一些示例数据中,我看到:

df.head()

x
date    
2017-12-18 07:01:15 20054.42
2017-12-18 07:01:24 20057.17
2017-12-18 07:01:32 20047.99
2017-12-18 07:01:40 20046.15
2017-12-18 07:01:49 20045.23

df.dtypes

x    float64
dtype: object

df.index

DatetimeIndex(['2017-12-18 07:01:15', '2017-12-18 07:01:24', '2017-12-18 
07:01:32', '2017-12-18 07:01:40', '2017-12-18 07:01:49', '2017-12-18 
07:01:58', '2017-12-18 07:02:06', '2017-12-18 07:02:14', '2017-12-18 
07:02:22', '2017-12-18 07:02:31',
           ...
           '2017-12-29 03:00:11', '2017-12-29 03:00:19', '2017-12-29 
03:00:42', '2017-12-29 03:00:50', '2017-12-29 03:00:57', '2017-12-29 
03:01:04', '2017-12-29 03:01:11', '2017-12-29 03:01:20', '2017-12-29 
03:01:27', '2017-12-29 03:01:34'], dtype='datetime64[ns]', name='date', 
length=99492, freq=None)

df.resample('D')是否可以在此df上运行,还是需要预处理? (比如设置与freq = None不同的东西) . 我已经看到解决方法和手动代码做同样的事情,但我想了解我的数据格式有什么问题 . 直接使用Pandas resample也是一个更长期的清洁 .

我得到的完整堆栈跟踪错误是(但我看不出哪个位置我做错了,它位于PeriodIndex的分支中):

AttributeError                            Traceback (most recent call last)
<ipython-input-120-5e18e9f3f0c1> in <module>()
     15 
     16 
---> 17 df['x'].resample('60S')

~/CODE/Python/anaconda2/envs/neo/lib/python3.6/site-      
packages/pandas/core/generic.py in resample(self, rule, how, axis, 
fill_method, closed, label, convention, kind, loffset, limit, base, on, 
level)
   5514         2000-01-01 00:03:00  0  4   8  12
   5515         """
-> 5516         from pandas.core.resample import (resample,
   5517                                           _maybe_process_deprecations)
   5518         axis = self._get_axis_number(axis)

~/CODE/Python/anaconda2/envs/neo/lib/python3.6/site-
packages/pandas/core/resample.py in <module>()
   1008 
   1009 
-> 1010 class TimeGrouper(Grouper):
   1011     """
   1012     Custom groupby class for time-interval grouping

~/CODE/Python/anaconda2/envs/neo/lib/python3.6/site-
packages/pandas/core/resample.py in TimeGrouper()
   1020         If axis is PeriodIndex
   1021     """
-> 1022     _attributes = Grouper._attributes + ('closed', 'label', 'how',
   1023                                          'loffset', 'kind', 
'convention',
   1024                                          'base')

AttributeError: type object 'Grouper' has no attribute '_attributes'