Home > other >  Filter out df by a row in another df
Filter out df by a row in another df

Time:12-07

I have two data frames. One contains the list of files (let's say this is df1) along with some data, and another one contains the list of files that I want (let's say this is df2). I want to create another df that contains only the wanted files and their data.

Any help is appreciated:))

df1:

enter image description here

df2:

enter image description here

Wanted_df

enter image description here

CodePudding user response:

You can merge them together by doing this:

wanted_df = df1.merge(df2, how = "right", left_on = 'File name', right_on = 'List of Wanted Files')

CodePudding user response:

You can use:

Wanted_df = df1[df1['File Name'].isin(df2['List of Wanted Files'])]

which produces:

  File Name Data about that File
0    File 1                apple
2    File 3           strawberry
4    File 5            starfruit
  • Related