Working with a +450K rows x 90 col data frame, I need to perform several pd.merge (Excel´s "vlookup") commands.
In contrast with existing solutions, I think that a new data frame with the mentioned dimensions for each merge isn't efficient.
How can I merge df1 with df2 on a new column inside df1?
So far my approach was to point the merge to a new column inside df1. without success.
import pandas as pd
df1=pd.DataFrame({'Campo':['C1','C2','C3'],'Plataformas':['C1-A','C2-A','C3-A']})
df2=pd.DataFrame({'Plataformas':['C1-A','C2-A','C3-A'],'Pozos':[5,10,15]})
df3=df1.merge(df2,on='Plataformas') #This works for the df3
t1['Num Pozos']=t1.merge(t2,on='Plataformas') #This didn't worked
DF1
Campo Plataformas
C1 C1-A
C2 C2-A
C3 C3-A
DF2
Plataformas Pozos
C1-A 5
C2-A 10
C3-A 15
New DF1 (Expected)
Campo Plataformas Pozos
C1 C1-A 5
C2 C2-A 10
C3 C3-A 15
To avoid df3 I tried:
df1['Num Pozos']=df1.merge(df2,on='Plataformas')
The output error was:
ValueError: Wrong number of items passed 4, placement implies 1
Any help is appreciated.
--- Edited question in response to @coldspeed --- In my opinion, the difference between similar questions is because of the other answers implies to create a new data frame which is not necessary in my case.