0

i have two data frames:
df1 :

     ID  COUNT
0   202485  6
1   215893  8
2   181840  8
3   168337  7

and another dataframe
df2:

ID
0   202485
1   215893
2   181840

i want to filter /left join the two dataframes:
desired result is

ID  COUNT
0   202485  6
1   215893  8
2   181840  8

i tried df1.merge(df2, how='inner', on='ID') : error like ou are trying to merge on object and int64 columns

also used isin, but didn't work.

list=df1['ID'].drop_duplicates().to_list()
df1[df1['ID'].isin(list)]

Any help?

elena.kim
  • 930
  • 4
  • 12
  • 22
kumarb
  • 39
  • 1
  • 6
  • 2
    Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Let's try May 17 '21 at 07:58

1 Answers1

0
df1 = pd.DataFrame({'ID':[202485,215893,181840,168337],'COUNT':[6,8,8,7]})
df2 = pd.DataFrame({"ID":[202485,215893,181840]})
out_df = pd.merge(df1,df2)
print(out_df)

This gives the desired result

      ID    COUNT
0   202485  6
1   215893  8
2   181840  8
Mohan
  • 46
  • 3
  • Thanks for the response. i want to pass dynamically. Hence by list name , i need to pass. While doing so, i get this error:You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat. May be some issue with format/data type – kumarb May 17 '21 at 08:23