相关疑难解决方法(0)

熊猫 drop_duplicates 不可散列的类型:'numpy.ndarray'、'set' 和 'list'

我正在尝试drop_duplicates在 a 的列上使用dataframe

A          len
['1', '2'] 2
['1', '2'] 2
['3']      1
['4', '5'] 2 
['4', '5'] 2
Run Code Online (Sandbox Code Playgroud)

结果dataframe应该是这样的

A          len
['1', '2'] 2
['3']      1
['4', '5'] 2 
Run Code Online (Sandbox Code Playgroud)

我试过了df.drop_duplicates('A', inplace=True),但有错误,

unhashable type: 'numpy.ndarray'
Run Code Online (Sandbox Code Playgroud)

我还A使用df['A'].apply(list)and转换为列表和集合df['A'].apply(set),然后使用drop_duplicates,但都失败了unhashable type: 'set' and 'list'。我想知道如何解决这个问题。

dataframe python-3.x pandas

2
推荐指数
1
解决办法
4930
查看次数

标签 统计

dataframe ×1

pandas ×1

python-3.x ×1