How to find duplicate names using pandas?

前端 未结 6 1274
無奈伤痛
無奈伤痛 2020-12-14 02:27

I have a pandas.DataFrame with a column called name containing strings. I would like to get a list of the names which occur more than once in the c

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 02:47

    I had a similar problem and came across this answer.

    I guess this also works:

    counts = df.groupby('name').size()
    df2 = pd.DataFrame(counts, columns = ['size'])
    df2 = df2[df2.size>1]
    

    and df2.index will give you a list of names with duplicates

提交回复
热议问题