Home > Net >  Compare each element of a DataFrame column with every element of another column
Compare each element of a DataFrame column with every element of another column

Time:03-29

I have two DataFrames of unequal lengths, Alerts and Labels. They both have a column named ID. I want to create a new column in the DataFrame Labels with true if its ID matches any ID in Alerts and false the ID is not present in Alerts.

CodePudding user response:

Assuming Labels and Alerts as dataframe names:

Labels['new_col'] = Labels['ID'].apply(lambda x:True if x in Alerts['ID'] else False)
  • Related