Getting an error message when merging two pandas dataframes on multiple columns for an inner join

Viewed 17

I am trying to merge two pandas dataframes on multiple columns, to form an inner join. I have written the following code:

'''
Merge SKU file with concatenated sale file on both Season Code and SKU ID. Inner Join
'''
df_sales_merged=pd.merge(df_sales_join, dfSKUlu, how='inner', left_on=['Season Code', 'SKU ID'], 
                          right_on=['Season Code', 'SKU ID'])

Instead of getting one dataframe with sales only for SKUs that are in both dataframes, I get a Key Error with all this gibberish, the very last line of which reads: KeyError: 'Season Code'.

What am I doing wrong?

1 Answers

I realized my error. On dfSkuLu, the variable was 'Season_Code' while on df_sales_join the variable was 'Season Code.' Once I adjusted by right_on list, everything merged beautifully.

Related