-1

I found this: Group DataFrame in 5-minute intervals. It works great, but my problem is that I have a second value, Altitude, which is important, so the resample code didn't work.

I want to create a 10 min mean for different Altitudes. The dataset looks like:

enter image description here

Is there a way to create this by groupby? With resample I get this:

enter image description here

The problem is that I also make a mean over the Altitude.

ALollz
  • 57,915
  • 7
  • 66
  • 89
S.Kociok
  • 168
  • 1
  • 14

1 Answers1

0

You can form the group yourself with Series.dt.floor, allowing you to group on that in addition to Altitude:

Sample Data

import pandas as pd
import numpy as np
df = pd.DataFrame({'Timestamp': pd.date_range('2019-04-04', freq='1.345min', 
                                              periods=20),
                   'Altitude': [1, 2]*10,
                   'val1': np.random.randint(1, 10, 20)})

df.groupby([df.Timestamp.dt.floor('10min'), 'Altitude']).mean()

                                  val1
Timestamp           Altitude          
2019-04-04 00:00:00 1         5.000000
                    2         3.250000
2019-04-04 00:10:00 1         5.000000
                    2         4.333333
2019-04-04 00:20:00 1         6.500000
                    2         5.000000
ALollz
  • 57,915
  • 7
  • 66
  • 89