Reputation: 10383
I have two data frames df1
and df2
taken from different databases. Each item in the dataframes is identified by an id
.
df1 = pd.DataFrame({'id':[10,20,30,50,100,110],'cost':[100,0,300,570,400,140]})
df2 = pd.DataFrame({'id':[10,23,30,58,100,110],'name':['a','b','j','d','k','g']})
there are some common products in both dataframes, in this case those with the ids: 10,30,100,110. I want to merge this information in one single dataframe, as this one:
df3 = pd.DataFrame({'id':[10,30,100,110],'name':['a','j','k','g'],'cost':[100,300,400,140]})
I was trying to do it with dictionaries and nested loops but I handling a rather big amount of data and it just take to long to do it that way.
Upvotes: 1
Views: 1141