I have 3 df like df1, df2, df3 and they read a .csv file. I want to combine df1 & df2 and then have the result do a lookup on df3 and pull the values that are the same in a certain key that's both in df3 and result. So basically a vlookup.
This is how I concatenated df1&df2:
result = pd.concat(frames,keys=['data1','data2'])
I performed the merge like this:
result = pd.merge(result, df3, left_on='ProducerID', right_index=True, how='left', sort=False)
But my results are these:
Key_x otherColumns Key_y otherColumns
L 0 5763460 NaN NaN NaN
L 1 5926058 NaN NaN NaN
L 2 5052233 NaN NaN NaN
L 3 5526565 NaN NaN NaN
L 4 5059073 NaN NaN NaN
L 5 5975975 NaN NaN NaN
I should mention, key is not in the index. I abbreviated the data. key is just a column in the middle of my data.
And these are snippets of what my data files look like:
df1
Column 1 Column 2 Column 3 Column n… Key Column …n
data1 data data data 5763460 data
data2 data data data 5926058 data
data1 data data data 5052233 data
df2
Column 1 Column 2 Column 3 Column n… Key Column …n
data1 data data data 5763460 data
data1 data data data 5926058 data
data2 data data data 5052233 data
df3
Key Column 1 Column 2
5763460 data data
5926058 data data
5052233 data data
result
Column 1 Column 2 Column 3 Column n… Key Column …n
data1 data data data 5763460 data
data1 data data data 5926058 data
data2 data data data 5052233 data
So result will look just like df1 just larger and grouped by the contents of Column 1 which are data1 and data2