简体   繁体   English

重新采样熊猫数据框

[英]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)位以及dateemaslow列。 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') setreset索引

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM