I have a reference table that I imported into a dataframe(df2) from a .csv. It's 3 columns and around 400 rows. I have another dataframe (df) that has many columns and rows. I am looking to lookup a value from the reference table and add it to the appropriate column in df.
The data format for the reference table:
MANUF PRODTYPE PRODCODE
ALPHA 1 ALPHA1
ALPHA 2 ALPHA2
BETA 1 BETA1
BETA 2 BETA2
DELTA 1 DELTA1
DELTA 2 DELTA2
The dataframe (df) is set up like this:
MANUF PRODTYPE SERIALNO PRODCODE INVENTORY
ALPHA 1 00001 5
ALPHA 2 00001 3
BETA 1 00001 4
DELTA 1 00001 8
ALPHA 2 00002 3
BETA 1 00002 4
DELTA 2 00001 9
DELTA 2 00002 9
DELTA 1 00002 8
BETA 2 00001 12
ALPHA 2 00003 3
I am trying to populate PRODCODE in df with the appropriate value based on MANUF and PRODTYPE in the reference table.
I tried:
df3 = df.merge(df2, how='left')
and
df3 = df2.merge(df, how='left')
but both gave me either inaccurate or incomplete merges.