pandas 에서 DataFrame 에서 중복 값 의 실현 을 감지 합 니 다.

본 고 는 어떻게 pandas 를 사용 하여 dataframe 의 중복 데 이 터 를 조회 하고 중복 여 부 를 판단 하 며 어떻게 무 거 운 지 상세 하 게 설명 한다.

DataFrame.duplicated(subset=None, keep='first')
subset:몇 필드 가 중복 된다 고 생각 되면 데이터 가 중복 되 며,그 필드 를 목록 으로 subset 뒤에 놓 으 십시오.기본 값 은 모든 필드 가 중복 데이터 로 반 복 됩 니 다.
keep:
  • 기본 값 은'first'입 니 다.즉,중복 데이터 가 있 으 면 첫 번 째 항목 은 False 로 정의 되 고 뒤의 중복 데 이 터 는 True 입 니 다
  • 'last',즉 중복 데이터 가 있 으 면 마지막 으로 나타 난 정 의 는 False 이 고 뒤의 중복 데 이 터 는 True 이다
  • False 라면 모든 중복 은 True
  • 다음 예
    
    df = pd.DataFrame({
        'brand': ['Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie'],
        'style': ['cup', 'cup', 'cup', 'pack', 'pack'],
        'rating': [4, 4, 3.5, 15, 5]
    })
    df 
    
    在这里插入图片描述
    
    #    keep="first",       False,      True
    #       keep,  keep    。
    df.duplicated()
    
      
    0    False
    1     True
    2    False
    3    False
    4    False
    dtype: bool
    
    # keep="last",,        False,      True
    df.duplicated(keep="last")
    
      
    0     True
    1    False
    2    False
    3    False
    4    False
    dtype: bool
    
    # keep=False,,      True
    df.duplicated(keep=False)
    
      
    0     True
    1     True
    2    False
    3    False
    4    False
    dtype: bool
    
    # sub  ,subset   
    #     brand      。
    df.duplicated(subset='brand')
    
      
    
    0    False
    1     True
    2    False
    3     True
    4     True
    dtype: bool
    
    
    #   brand  brand style       。
    df.duplicated(subset=['brand','style'])
    
      
    
    0    False
    1     True
    2    False
    3    False
    4     True
    dtype: bool
    
    
    #       ,      
    df[df.duplicated()]
    
    在这里插入图片描述
    
    #         。
    df.duplicated().sum()
    
      
    1
    
    pandas 에서 DataFrame 에서 중복 값 을 검출 하 는 실현 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 pandas DataFrame 에서 중복 값 을 검출 하 는 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!

    좋은 웹페이지 즐겨찾기