Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique values based on multiple columns

I have 2 columns which contains duplicate entries. See example below. I want to remove duplicates from both columns Original Column

MatchN  Striker
1000887 DA Warner
1000887 DA Warner
1000887 TM Head
1000887 TM Head

I would like to finally get the result as

MatchN  Striker
1000887 DA Warner
1000887 TM Head

I tried using

np.df[["MatchN"],["Striker"]].unique()

but it does not work.

Can anyone please suggest best way to get to the desired result?

like image 264
Anoop Mahajan Avatar asked Jul 30 '26 13:07

Anoop Mahajan


1 Answers

IIUC you need DataFrame.drop_duplicates() method:

In [69]: df = df.drop_duplicates(['MatchN','Striker'])

In [70]: df
Out[70]:
    MatchN    Striker
0  1000887  DA Warner
2  1000887    TM Head
like image 170
MaxU - stop WAR against UA Avatar answered Aug 01 '26 02:08

MaxU - stop WAR against UA