In Pandas, after groupby the grouped column is gone

前端 未结 4 726
萌比男神i
萌比男神i 2021-01-04 09:48

I have the following dataframe named ttm:

    usersidid   clienthostid    eventSumTotal   LoginDaysSum    score
0       12          1               60                


        
4条回答
  •  [愿得一人]
    2021-01-04 10:46

    You simply need this instead:

    ttm.groupby(['clienthostid'], as_index=False, sort=False)[['LoginDaysSum']].apply(lambda x: x.iloc[0] / x.iloc[1]).reset_index()
    

    The double [[]] will turn the output into a pd.Dataframe instead of a pd.Series.

提交回复
热议问题