【发布时间】:2021-10-08 16:50:33
【问题描述】:
我有这样的数据:
id season team wins losses goals
0 0 2006-2007 Manchester United 28 5 83
1 1 2006-2007 Chelsea 24 3 64
2 2 2006-2007 Liverpool 20 10 57
.
.
238 238 2017-2018 Stoke City 7 19 35
239 239 2017-2018 West Bromwich Albion 6 19 31
我正在努力寻找每个赛季进球最多的球队。
目标输出:
team season
Manchester United 2006-2007 83
Manchester United 2007-2008 80
Liverpool 2008-2009 77
.
.
Manchester City 2017-2018 106
我试过了,
df.groupby(['team','season'])['goals'].sum().sort_values(ascending = False).head(10)
team season
Manchester City 2017-2018 106
Chelsea 2009-2010 103
Manchester City 2013-2014 102
Liverpool 2013-2014 101
Manchester City 2011-2012 93
Manchester United 2011-2012 89
Tottenham Hotspur 2016-2017 86
Manchester United 2012-2013 86
2009-2010 86
Chelsea 2016-2017 85
Name: goals, dtype: int64
这给了我一个球队在所有赛季中的最高总进球数。一年在这里重复,我不希望岁月重复。
【问题讨论】:
标签: python pandas dataframe pandas-groupby