Home > Software engineering >  How to lookup different dataframes and return the values?
How to lookup different dataframes and return the values?

Time:11-20

Im trying to lookup the index in two different datframes and return the values.

For example, in df1 i would like to lookup in df2 and return the same index and values.

DF1 enter image description here

DF2 enter image description here

I would like my result to be like this.

RESULTS enter image description here

CodePudding user response:

Try this

new_df = df2[df2.ID == [list(df1.ID)]]

CodePudding user response:

Get the IDs from df2 where the ID is in df1

filtered_df = df2[(df2['ID'].isin(df1['ID']))]
  • Related