0

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

Chris
  • 93
  • 5

2 Answers2

1

Get the IDs from df2 where the ID is in df1

filtered_df = df2[(df2['ID'].isin(df1['ID']))]
  • work but what if i df1 98,95,88,85,81,86,100. how do i return the values in that order. Some one the numbers or not in order but i would like to keep in the order of df1 – Chris Nov 19 '22 at 22:21
  • there isn't an easy way to do custom sorting in pandas https://stackoverflow.com/questions/13838405/custom-sorting-in-pandas-dataframe – Nicholas Hansen-Feruch Nov 19 '22 at 22:58
1

Try this

new_df = df2[df2.ID == [list(df1.ID)]]
CharlieBONS
  • 216
  • 7