Reputation: 74
I am trying to merge tables based on a key that is common to them using pandas and I am constantly getting the error :
KeyError: 'Host Key of Allocated Locations'
Table one has data: highlighted value is the 'Host Key of Allocated Locations'. Also, it has duplicate values which I want to have as they will be needed in further analysis.
Table 2: highlighted value is the PK key
df3 = pd.merge(timetable_2020_df, joined_uom_space_df, on='Host Key of Allocated Locations', how='left')
I tried but I cannot understand what the issue is.
duplicate data is :
Upvotes: 0
Views: 38
Reputation: 5565
The on
keyword only works when you have the same named column in both dataframes. Your right
dataframe does not have the 'Host...' column, hence a keyerror is being raised.
You will need to use left_on
and right_on
keywords to specify the joining columns in your left and right dataframes.
Upvotes: 1