How to keep original index of a DataFrame after groupby 2 columns?

后端 未结 3 1171
时光说笑
时光说笑 2021-02-13 03:26

Is there any way I can retain the original index of my large dataframe after I perform a groupby? The reason I need to this is because I need to do an inner merge back to my ori

3条回答
  •  [愿得一人]
    2021-02-13 04:03

    I think you are are looking for transform in this situation:

    df['count'] = df.groupby(['col1', 'col2'])['col3'].transform('count')
    

提交回复
热议问题