Drop all duplicate rows across multiple columns in Python Pandas

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

    use groupby and filter

    import pandas as pd
    df = pd.DataFrame({"A":["foo", "foo", "foo", "bar"], "B":[0,1,1,1], "C":["A","A","B","A"]})
    df.groupby(["A", "C"]).filter(lambda df:df.shape[0] == 1)
    

提交回复
热议问题