pandas drop_duplicates unhashable type: 'numpy.ndarray', 'set' and 'list'

前端 未结 1 1986
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 04:25

I am trying to use drop_duplicates on a column of a dataframe,

A          len
[\'1\', \'2\'] 2
[\'1\', \'2\'] 2
[\'3\']      1
[\'4\',          


        
1条回答
  •  有刺的猬
    2021-01-27 04:47

    You need tuple:

    df['A'].apply(tuple)
    

    So use duplicated with boolean indexing:

    df = df[~df['A'].apply(tuple).duplicated()]
    print (df)
            A  len
    0  [1, 2]    2
    2     [3]    1
    3  [4, 5]    2
    

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