Given this dataframe :
DriverId time SPEED
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.72413
i want add column to count number of speed under 40 km/h for each driver so i've tried this :
y[y.SPEED<40].count()
it shows this :
SPEED 4721
dtype: int64
and it is not exactly what i want ,the expexted result must be like this :
DriverId SPEED count
0 15.20 2
32.850000
89.633333
88.166667
118.016667
... ... ...
88 79.566667 1
59.383333
89.133333
59.966667
25.72413
my dataframe was a serie which i transform to dataframe
y.info()
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 15082 entries, (0, Timestamp('2021-04-16 21:40:00+0000', tz='UTC')) to (88, Timestamp('2021-04-27 07:34:00+0000', tz='UTC'))
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 SPEED 15082 non-null float64
dtypes: float64(1)
memory usage: 922.5 KB