[英]Resample Pandas DataFrame
I have this: 我有这个:
date emaslow
105857 2017-10-24 22:50:00 0.000037
105858 2017-10-24 22:55:00 0.000037
105859 2017-10-24 23:00:00 0.000037
It is a huge data set, this is only the tail(3)
bit and the date
and emaslow
columns. 这是一个庞大的数据集,仅是tail(3)
位以及date
和emaslow
列。 I am trying to resample this a little bit so I get a smoother plot. 我试图对此进行一些重采样,以便获得更平滑的图。 But no matter what I do, I get the nasty: 但是无论我做什么,我都会感到讨厌:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but
got an instance of 'RangeIndex'
I tried to set
and reset
the index with df.reset_index()
and df.set_index('date')
我尝试使用df.reset_index()
和df.set_index('date')
set
和reset
索引
But with no luck. 但是没有运气。
I am trying to get a smoother, version of the red plot. 我正在尝试获得更平滑的红色版图。 The blue one is wrong and it is just a place holder. 蓝色的是错误的,它只是一个占位符。
Are you looking for resample
, you can change the sum
to mean
or whatever you need. 您在寻找resample
,可以将sum
更改为mean
或任何您需要的值。
df.set_index('date').resample('10T').sum()
Out[502]:
emaslow
date
2017-10-24 22:50:00 0.000074
2017-10-24 23:00:00 0.000037
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.