如何每5分钟重新采样一次数据帧

时间:2018-10-21 15:30:53

标签: python pandas dataframe

我有一个月(不包括星期六和星期日)的数据框,该数据框每1分钟记录一次。

                         v1         v2  
2017-04-03 09:14:00     35.7       35.4  
2017-04-03 09:15:00     34.7       34.4
2017-04-03 09:16:00     28.1       28.5
2017-04-03 09:17:00     28.3       28.2
2017-04-03 09:18:00     28.5       28.3
2017-04-03 09:19:00     28.6       28.1
2017-04-03 09:20:00     28.7       28.4
      ...               ...        ...
2017-04-03 16:25:00     80.7       80.6
2017-04-03 16:26:00     82.5       82.3
2017-04-03 16:27:00     81.6       81.1
2017-04-03 16:28:00     82.7       82.4
2017-04-03 16:29:00     81.7       81.5
      ...               ...        ...
2017-04-04 09:14:00     24.3       24.2  
2017-04-04 09:15:00     25.6       25.5
      ...               ...        ...
2017-04-04 16:29:00     67.0       67.2
      ...               ...        ...
2017-04-28 09:14:00     31.7       31.4  
2017-04-28 09:15:00     31.5       31.0
      ...               ...        ...
2017-04-28 16:29:00     33.2       33.5

如何每天对数据重新采样以获取第一个值和最后一个值以及每5分钟的值。不会发生诸如和,均值等统计信息。 df.groupby(df.index.date).resample('5T').first()遗漏了最后几个值和起始值

所需的输出:

                        v1         v2
2017-04-03 09:14:00     35.7       35.4  
2017-04-03 09:15:00     34.7       34.4  
2017-04-03 09:20:00     42.1       43.4
      ...                ..         ..
2017-04-03 16:25:00     80.7       80.6
2017-04-03 16:29:00     82.7       82.6
      ...               ...        ...
2017-04-04 09:14:00     24.3       24.2
2017-04-04 09:15:00     25.6       25.5
2017-04-04 09:20:00     82.7       82.6
      ...                ..         ..
2017-04-04 16:25:00     69.7       69.6
2017-04-04 16:29:00     70.2       70.6
      ...               ...        ...
2017-04-28 09:14:00     31.7       31.4 
2017-04-28 09:15:00     31.7       31.4 
2017-04-28 09:20:00     32.8       33.0
      ...               ...        ...
2017-04-28 16:25:00     32.7       32.6
2017-04-28 16:29:00     33.0       30.7

0 个答案:

没有答案