Skip to content
Advertisement

Delete the rows that have the same value in the columns Dataframe

I have a dataframe like this :

origin destination
germany germany
germany italy
germany spain
USA USA
USA spain
Argentina Argentina
Argentina Brazil

and I want to filter the routes that are within the same country, that is, I want to obtain the following dataframe :

origin destination
germany italy
germany spain
USA spain
Argentina Brazil

How can i do this with pandas ? I have tried deleting duplicates but it does not give me the results I want

Advertisement

Answer

Use a simple filter:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement