ht表概览
目标:对每个用户id
分组,取出totalCont
最大时的热门+位置
。
方法1:
ht.groupby('用户id').apply(lambda x: x.loc[x.totalCount.idxmax(), '热门+位置'])
当数据量大时,非常慢!
方法2:
对totalCount
排序,然后去除用户id重复项,保留第一项(即保留了totalCount
最大时的用户id)。
ht.sort_values('totalCount', ascending=False).drop_duplicates(subset=['用户id'], keep='first')['热门+位置']