Вы можете использовать groupby()
, agg()
и mean()
:
df.groupby(['Grade','HeatNumber']).agg({'Ontime': 'max'}).mean(level=0)
Вот рабочий пример:
df = pd.DataFrame({'Grade': ['150HP', '150HP', '150HP', 'A100C', 'A100C', 'A100X', 'A100X', 'A100X', 'LOWO2A100'],
'HeatNumber': ['19258', '19258', '19260','19187', '19787', '19261', '19261', '19237', '19262'],
'Ontime': [45.8, 39.5, 42.8, 31.6, 65.5, 25.4, 65.1, 21.5, 32.4]})
Дает:
Grade HeatNumber Ontime
0 150HP 19258 45.8
1 150HP 19258 39.5
2 150HP 19260 42.8
3 A100C 19187 31.6
4 A100C 19787 65.5
5 A100X 19261 25.4
6 A100X 19261 65.1
7 A100X 19237 21.5
8 LOWO2A100 19262 32.4
Применение строки выше:
Ontime
Grade
150HP 44.30
A100C 48.55
A100X 43.30
LOWO2A100 32.40