2017-11-23 12 views
0

나는 항목이 집합 인 시리즈를 가지고 있습니다. pandas.Series.drop_duplicates()을 사용하여 중복 된 항목을 모두 제거하려고하지만 오류가 발생합니다. 다음은 그 예이다 :엔트리가 집합 일 때 판다에서 중복을 제거하는 방법

TypeError: unhashable type: 'set'

내가 좀하고 싶습니다 반면 :

0 {1, 2, 3} 
1 {4, 5, 6} 

이 버그가

import pandas as pd 
ser = pd.Series([{1,2,3}, {4,5,6}, {4,5,6}]) 
ser.drop_duplicates() 

마지막 줄은 다음과 같은 예외가 있습니다? 아니면 이것을 달성 할 다른 방법이 있습니까?

답변

1

다음 duplicated

ser[~ser.astype(str).duplicated(keep='first')] 
Out[170]: 
0 {1, 2, 3} 
1 {4, 5, 6} 
dtype: object 

추가 정보를 astype(str)를 사용하여 우리를 보자

ser.astype(str).duplicated(keep='first') 
Out[171]: 
0 False 
1 False 
2  True 
dtype: bool