Pandas: calculating the mean values of duplicate entries in a dataframe

前端 未结 2 1969
情深已故
情深已故 2021-02-02 13:00

I have been working with a dataframe in python and pandas that contains duplicate entries in the first column. The dataframe looks something like this:

    sampl         


        
相关标签:
2条回答
  • 2021-02-02 13:35

    Groupby will work.

    data.groupby('sample_id').mean()
    

    You can then use reset_index() to make look exactly as you want.

    0 讨论(0)
  • 2021-02-02 13:41

    groupby the sample_id column and use mean

    df.groupby('sample_id').mean().reset_index()
    or
    df.groupby('sample_id', as_index=False).mean()

    get you

    0 讨论(0)
提交回复
热议问题