Drop all duplicate rows across multiple columns in Python Pandas

前端 未结 6 2067
北海茫月
北海茫月 2020-11-21 21:00

The pandas drop_duplicates function is great for \"uniquifying\" a dataframe. However, one of the keyword arguments to pass is take_last=True

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 21:24

    If you want result to be stored in another dataset:

    df.drop_duplicates(keep=False)
    

    or

    df.drop_duplicates(keep=False, inplace=False)
    

    If same dataset needs to be updated:

    df.drop_duplicates(keep=False, inplace=True)
    

    Above examples will remove all duplicates and keep one, similar to DISTINCT * in SQL

提交回复
热议问题