pandas filtering using isin function
问题 I have two dataframe as shown below df1: ID Name 1 Sachin 2 Kholi 3 Dravid df2: ID Run 1 20 2 60 2 10 1 5 From the above I want to filter df1 by only taking unique ids in df2: Expected output: ID Name 3 Dravid I tried below code def diff(first, second): second = set(second) units_in_unit_table = [item for item in first if item not in second] return units_in_unit_table id_df2 = diff(df2, df1) df3 = df1[df1['ID'].isin(id_df2)] 回答1: It seems your solution should be simplify by pass unique values