I am trying to merge to excel file in Pandas.
import pandas as pd
import numpy as np
upload_raw = pd.read_excel(r'C:\Users\Desktop\Upload Raw Data.xlsx',
sheet_name = 'Upload',
header = 0,
index_col = 0,
)
mapping = pd.read_excel(r'C:\Users\Desktop\Mapping.xlsx',
sheet_name = 'Mapping',
header = 0,
index_col = 0,
)
display(upload_raw)
display(mapping)
upload_lookup=upload_raw.merge(mapping,on ='BRANCH',how = 'outer' )
display(upload_lookup)
I continue to get the KeyError: 'BRANCH'. I checked the values of the columns all are text. The Mapping file has 3 columns while the upload has around 4 columns.
Upload Raw data
BRANCH DEPT CREAT_TS RAF_IND
AA &CR 2018-06-22-06.48.49.601000
03 CUE 2018-06-22-11.43.29.859000
90 T0L 2018-06-22-11.54.52.633000
Mapping Data:
BRANCH UNIT MASTER
03 MAS CoE
04 NAS ET
05 ET ET
In the error message these are quite prominent.
# validate the merge keys dtypes. We may need to coerce
# work-around for merge_asof(right_index=True)
# duplicate columns & possible reduce dimensionality
How do i avoid this issue.
I even tried left_on = 'True', right_on = 'True'
left_key = 'lkey', right_key = 'rkey'. I get the error 'rkey not found
Regards, Ren.