- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个名为 aus
的数据框,如下所示:
+--------------+-------------+
| | link clicks |
+--------------+-------------+
| created_time | |
| 2015-07-20 | 8600 |
| 2015-07-21 | 11567 |
| 2015-07-22 | 1809 |
| 2015-07-23 | 7032 |
| 2015-07-26 | 23704 |
+--------------+-------------+
我将索引设为 DateTimeIndex,如下所示:aus.index = pd.to_datetime(aus.index)
然后我运行这样的检查:type(aus.index)
给定的输出是 pandas.tseries.index.DatetimeIndex
然后当我尝试像这样将索引重新抽样为数周时aus.index = aus.resample('w', how='sum', axis=1)
我遇到了以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-310-3268a3f46a19> in <module>()
----> 1 aus.index = aus.resample('w', how='sum', axis=1)
/usr/local/lib/python2.7/site-packages/pandas/core/generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base)
3264 fill_method=fill_method, convention=convention,
3265 limit=limit, base=base)
-> 3266 return sampler.resample(self).__finalize__(self)
3267
3268 def first(self, offset):
/usr/local/lib/python2.7/site-packages/pandas/tseries/resample.pyc in resample(self, obj)
100 return self.obj
101 else: # pragma: no cover
--> 102 raise TypeError('Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex')
103
104 rs_axis = rs._get_axis(self.axis)
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex
我之前的类型检查说我有正确的索引,但 resample 函数并不这么认为。有什么想法吗?
最佳答案
axis=1 表示它正在尝试对列重新采样(这不是 DatetimeIndex)。
In [11]: df.columns
Out[11]: Index([u'link clicks'], dtype='object')
In [12]: type(df.columns)
Out[12]: pandas.core.index.Index
使用轴=0:
In [21]: aus.resample('w', how='sum', axis=0)
Out[21]:
link clicks
created_time
2015-07-26 52712
注意:这是重新采样的默认值:
In [22]: aus.resample('w', how='sum')
Out[22]:
link clicks
created_time
2015-07-26 52712
关于python - Pandas 重采样功能不适用于 DateTimeIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32573993/
在 pandas datetimeindex 中,dayofweek和 weekday似乎是一样的。他们只是彼此的别名吗?我发现了这些功能 here 最佳答案 根据pandas源码定义的Datetim
到目前为止,我有 EdChum 提供的以下代码: In [1]: df = pd.DataFrame({'a': [None] * 6, 'b': [2, 3, 10, 3, 5, 8]}) df["
我有一个按日期时间索引的数据框。我正在尝试创建某种过滤器,它只提供包含特定时间的帧。 例如,所有包含“09:30”的帧 df.dtypes open float64 high
不规则时间序列 data存储在 pandas.DataFrame 中.一个 DatetimeIndex已经设置好了。我需要索引中连续条目之间的时间差。 我以为就这么简单 data.index.diff
如何将 DatetimeIndex 更改为像这样的简单数据框: month 0 2013-07-31 1 2013-08-31 2 2013-09-30 3 2013-10-3
我在 pandas 数据框中有多个以下格式的日期列表: col1 col2 1 [DatetimeInde
我有一个 DatetimeIndex 对象,它由两个日期组成,如下所示: import pandas as pd timestamps = pd.DatetimeIndex(['2014-1-1',
我有一个数据框,使用以下代码生成: time_index = pd.date_range(start=datetime(2013, 1, 1, 3), e
我想绘制一个 pandas 系列,其索引是不计其数的 DatatimeIndex。我的代码如下: import matplotlib.dates as mdates index = pd.Dateti
Pandas 在系列/数据帧上有一个 resample 方法,但似乎没有办法单独对 DatetimeIndex 进行重采样? 具体来说,我有一个每日 Datetimeindex,其中可能缺少日期,我想
我已将一组 Excel 文件中的文件名中的日期提取到 DateTimeIndex 对象列表中。我现在需要将每个提取的日期写入我从每个 Excel 工作表创建的数据框的新日期列。我的代码的工作原理是将新
我想计算 DateTimeIndex 中时间之间的时间差 import pandas as pd p = pd.DatetimeIndex(['1985-11-14', '1985-11-28', '
我有一个 pandas.DatetimeIndex ,例如: pd.date_range('2012-1-1 02:03:04.000',periods=3,freq='1ms') >>> [2012
我在单独的 pandas.dataframe 中有两个时间序列,第一个 - series1与第二个条目相比,条目较少且开始数据时间不同 - series2 : index1 = pd.date_ran
我在数据框中有一个带有 DatetimeIndex 的时间序列,如下所示: import pandas as pd dates= ["2015-10-01 00:00:00", "2
当我使用pandas.date_range()时,有时我的时间戳有很多我不想保留的毫秒数。 假设我... import pandas as pd dr = pd.date_range('2011-01
我有一个带有 DateTimeIndex 的 Pandas 数据框和一个名为 WEEKEND 的空列。 如果索引中的日期时间是周末,我想将该列的值设置为“YES”,以便生成的数据帧如下所示: TIME
我有一个包含 12 个值的数据框,我想将其转换为 DatetimeIndex 类型 months = df['date'] #e.g. '2016-04-01' idx = pd.date_range
我处理一个DataFrame,其索引是字符串,年月,例如: index = ['2007-01', '2007-03', ...] 但是,索引未满。例如缺少 2007-02。我想要的是使用完整索引重新
我一直被这样的问题困扰。我有一套客流量的观察。数据存储在.xlsx文件中,结构如下:观察日期、时间、车站名称、登机、下车。 我想知道如果我只需要日期时间的“时间”组件,是否可以从此类数据创建带有 Da
我是一名优秀的程序员,十分优秀!