python 取分组的最大值max

import pandas as pd 

import nump as np

# 取分组的max = 取大小排序后的top1 (head(1))

result = result.sort_values(by=['cnt'], ascending=[False]).reset_index(drop=True)

result_max = result.groupby(['A', 'B']).head(1) 

# 比取idmax后再df[]便捷一点

你可能感兴趣的:(python)