【发布时间】:2020-07-02 11:54:38
【问题描述】:
我有一个csv file that contains information about games played in the last 5 decades。我将在过去几年的每个赛季中找到获胜的球队。所以我应该检查积分列,但如果有两支球队的最高分相同,我应该检查goal_difference。
df3=pd.DataFrame(df_laliga.groupby('season')[['points']].max(axis=1).reset_index())
result=pd.merge(df3,df_laliga,how='inner',on=['points','season'])
result=result[['season','club']].set_index('season')
del result.index.name
结果就是这种格式
在 2006-07 赛季,两支球队得分相同,并且有两支球队。我按照下面的方式尝试过,但问题没有给我正确的结果。
df3=pd.DataFrame(df_laliga.groupby('season')[['points','goal_difference']].max(axis=1).reset_index())
原始数据:
【问题讨论】:
-
你能提供原始(原始)数据吗?
-
当然。我放了一些表格图片和有问题的数据链接。
标签: python pandas dataframe max pandas-groupby