-2

i want add column to my dataframe to count for each driver mean(speed) < 23

this is my code to calculate mean(speed) on each 1 min and groupby driver

rawData.groupby('DriverId').resample("1T", on='time').SPEED.mean() 

the result is :

 DriverId  time                     
0         2021-04-16 21:40:00+00:00     58.500000
          2021-04-16 21:41:00+00:00     32.850000
          2021-04-16 21:42:00+00:00     89.633333
          2021-04-16 21:43:00+00:00     88.166667
          2021-04-16 21:44:00+00:00    118.016667
                                          ...    
88        2021-04-27 07:30:00+00:00     79.566667
          2021-04-27 07:31:00+00:00     59.383333
          2021-04-27 07:32:00+00:00     89.133333
          2021-04-27 07:33:00+00:00     59.966667
          2021-04-27 07:34:00+00:00     25.724138

now i want add column 'lowSpeedEvent' to count how many mean(speed)<23

rawData.lowspeed=(rawData.groupby('DriverId').resample("1T", on='time').SPEED.mean() < 23).count()

the result is

rawData.lowspeed
15082

but i want to calculate foe each driver not a total for all drivers

yyou123
  • 7
  • 4

1 Answers1

0

You can write something along the lines

rawData[rawData['Speed']<rawData['MeanSpeed']].count()
JuR
  • 113
  • 4
  • thanks i find my answer : ` rawData['lowspeed']=(rawData.groupby('DriverId').resample("1T", on='time').SPEED.mean() <23).count(True) – yyou123 Aug 16 '21 at 11:49