오늘의 인기 글
최근 글
최근 댓글
Today
Total
05-19 08:40
관리 메뉴

우노

[Python] Pandas DataFrame 중복 행, 열 제거 본문

Language/Python

[Python] Pandas DataFrame 중복 행, 열 제거

운호(Noah) 2021. 10. 9. 00:44

중복 행 제거

  • 모든 열을 기준으로 중복되는 행 제거

      df.drop_duplicates()

열 지정하여 중복 행 제거

  • 지정된 열을 기준으로 중복되는 행 제거

      df.drop_duplicates(['col1','col2'])

중복되는 데이터 중에서, 남길 대상 지정

# 첫 번째 데이터만 남기기
ex.drop_duplicates(['col1'], keep = 'first')

# 마지막 데이터만 남기기
ex.drop_duplicates(['col1'], keep = 'last')

# 모두 제거
ex.drop_duplicates(['col1'], keep = False)

참고

Comments