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

前端 未结 2 1968
情深已故
情深已故 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: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

提交回复
热议问题