Drop all duplicate rows across multiple columns in Python Pandas

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

    Try these various things

    df = pd.DataFrame({"A":["foo", "foo", "foo", "bar","foo"], "B":[0,1,1,1,1], "C":["A","A","B","A","A"]})
    
    >>>df.drop_duplicates( "A" , keep='first')
    

    or

    >>>df.drop_duplicates( keep='first')
    

    or

    >>>df.drop_duplicates( keep='last')
    

提交回复
热议问题