Ashutosh
Ashutosh

Reputation: 426

pandas drop duplicates doesn't return dataframe with duplicates removed

I have a dataframe:

df = pd.Dataframe({'src':['A','B','C'],'trg':['A','C','B'],'wgt':[1,3,7]})

I want to drop the duplicates from this dataframe for columns src and trg

df = df.drop_duplicates(subset=['src','trg'],keep='first',inplace=False)

This should drop the first row where src=A and trg='A'

But this is not happening. There is no change in the dataframe. What am I doing wrong ?

Upvotes: 0

Views: 85

Answers (1)

Junior Yao
Junior Yao

Reputation: 31

TO remove the duplicate, you can refer to the following example which I have solved on pyNb enter image description here

Or use df = df[df['src'] != df['trg']]

Upvotes: 1

Related Questions