Python 如何从datetimestamp列开始每隔5分钟对数据帧中的一列求平均值?

Python 如何从datetimestamp列开始每隔5分钟对数据帧中的一列求平均值?,python,pandas,Python,Pandas,我有一个如下所示的数据帧: Event time Event type Ignore Price 0 1526076933917 kline 0 18202362 1 1526076937493 kline 0 18202367 Event time Event type Ignore Price 0 2018-05-11 22:15:3

我有一个如下所示的数据帧:

      Event time Event type  Ignore       Price  
0  1526076933917      kline       0       18202362   
1  1526076937493      kline       0       18202367
               Event time Event type  Ignore        Price  
0 2018-05-11 22:15:33.917      kline       0       18202362   
1 2018-05-11 22:15:37.493      kline       0       18202367   
我使用以下行将“事件时间”列转换为人类可读的格式:

df['Event time'] = pd.to_datetime(df['Event time'], unit='ms')
现在dataframe如下所示:

      Event time Event type  Ignore       Price  
0  1526076933917      kline       0       18202362   
1  1526076937493      kline       0       18202367
               Event time Event type  Ignore        Price  
0 2018-05-11 22:15:33.917      kline       0       18202362   
1 2018-05-11 22:15:37.493      kline       0       18202367   

从这里开始,我如何从“事件时间”列中获取每5分钟的“价格”平均值,并保持所有其他列不变

您可以使用
pd.gropper
,使用
freq
5分钟(
freq='5min'
):

你会得到:

               Event time Event type  Ignore     Price    avgPrice
0 2018-05-11 22:15:33.917      kline       0  18202362  18202364.5
1 2018-05-11 22:15:37.493      kline       0  18202367  18202364.5

非常感谢您@saculand@AntonvBR!