【发布时间】:2022-06-12 06:18:23
【问题描述】:
我关注 this answer 但是,我无法为我的目的获得正确的语法
df.head()
country league Win DNB O 1.5 U 4.5
113 Iceland Urvalsdeild Women 3.19 3.43 4.89 2.10
135 Belgium Jupiler League 1.99 1.99 3.59 2.40
165 Brazil Serie D 1.71 1.98 3.80 1.90
238 Czech Republic U19 League 2.90 2.90 4.70 2.25
244 China Jia League 2.42 0.94 4.80 2.00
我想要country
,league
max of ('Win', 'DNB', 'O 1.5')
,min of ('U 4.5')
我在努力
df= df.groupby('country', 'league).agg({'Win':'max', 'DNB':'max', 'O 1.5':'max', 'U 4.5': 'min'})[['Win', 'DNB', 'O 1.5', 'U 4.5']].reset_index()
但是我收到了SyntaxError: invalid syntax
正确的语法是什么?
【问题讨论】:
-
我不知道其余的是否正确,但是您的
groupby
是错误的。您需要将其更改为:df.groupby(['country', 'league']).agg(...
标签: python dataframe group-by max min