如何获取与最大值一起显示的相应索引

How to get the corresponding index shown together with the max value

我有这套table

MonthNum     Trips
1             45000
2             23000
3             78000
4             89000
5             98000
6             96000
7             47000

当我运行以下代码时:我得到最大值的结果但不是相应的月份。 我可以得到一些帮助吗?

*df = pd.read_csv('data.csv') 
 df = df[['MonthNum','Trips']]
 df = df.groupby('MonthNum').sum().max()
 print(f" The overall busiest month : \n {df}", )*

Returns 以下:我需要在值旁边显示月份 整体最繁忙的月份: 行程 98000

如果我没理解错的话,你可以使用.idxmax():

df = df.groupby("MonthNum", as_index=False).sum()
print(df.loc[df["Trips"].idxmax()])

打印:

MonthNum        5
Trips       98000
Name: 4, dtype: int64