Home > Software design >  Finding Matched results in CSV
Finding Matched results in CSV

Time:09-04

I have my data in this format :

Harvard MIT
David Troy
Siri Charlie
Troy David
Alexa Cortana
Cortana Man
Animal David

and I want my results to be in :

Harvard MIT Output
David Troy David
Harvard MIT Troy
David Troy Cortana
Siri Charlie
Troy David
Alexa Cortana
Cortana Man

I don't care the order I get the name, just I need the list of person who are attending both institutions. I have them stored in same csv file but different column.

Python is my preferred language. Or I have git bash Installed on my windows either. I need a solution.

CodePudding user response:

The following line of code should solve your problem.

df['Output'] = df['Harvard'].loc[df['Harvard'].isin(df.MIT.values.tolist())]

You can sort the Output-column afterwards, if you want to.

  • Related