'Type error for a column that exists within the dataframe I am trying to call
Essentially, I am getting a key error in my jupyter notebook when trying to merge two data frames. As I understand it, a key error will only occur if said column I am trying to merge on doesn't exist. The column I am trying to merge on most certainly exists and I am confident that it is spelled correctly. For more context, I am merging my 'region' data frame onto my main 'sales' data frame on 'region_id' (the column associated with the key error).
sales = sales.merge(region,on='region_id')
sales.head()
sales csv was imported as
sales=pd.read_csv('C:/Users/tjwav/OneDrive/Desktop/data/sales.csv')
region csv was imported as
region=pd.read_csv('C:/Users/tjwav/OneDrive/Desktop/data/region.csv')
Sales table
product_id time_id customer_id store_id store_sales store_cost
0 337 371 6280 2 1.50 0.5100
1 1512 371 6280 2 1.62 0.6318
2 963 371 4018 2 2.40 0.7200
3 181 371 4018 2 2.79 1.0323
4 1383 371 4018 2 5.18 2.1756
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|