Drop all duplicate rows across multiple columns in Python Pandas

前端 未结 6 2052
北海茫月
北海茫月 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:10

    This is much easier in pandas now with drop_duplicates and the keep parameter.

    import pandas as pd
    df = pd.DataFrame({"A":["foo", "foo", "foo", "bar"], "B":[0,1,1,1], "C":["A","A","B","A"]})
    df.drop_duplicates(subset=['A', 'C'], keep=False)
    

提交回复
热议问题