その先にあるもの…

[PYTHON] 데이터프레임 중복 확인 본문

프로그래밍/Python

[PYTHON] 데이터프레임 중복 확인

specialJ 2020. 6. 26. 16:38

df = [[1 ,2, 3, 4, 5],

       [1, 2, 3, 4, 5],
       [1, 2, 4, 5, 6],
       [7, 8, 9, 10, 11],
       [12, 13, 14, 15, 16]]

 

#중복된 행 확인 ( 동일한 데이터 체크 )
data.duplicated()

0    False
1     True
2    False
3    False
4    False
dtype: bool

 

#특정 열을 선택하여 중복된 행 확인

data.duplicated( ['col1', 'col2'] )

0    False
1     True
2     True
3    False
4    False
dtype: bool

 


#중복된 행만 출력
data[data.duplicated()]

   col1  col2  col3  col4  col5
1     1     2     3     4     5

 


#중복된 행은 하나만 남기고 제거하기
data.drop_duplicates(inplace = True)

   col1  col2  col3  col4  col5
0     1     2     3     4     5
2     1     2     4     5     6
3     7     8     9    10    11
4    12    13    14    15    16

Comments