dear sirPlease review all the data in my dataframe that is related to primary key (pk) and foreign key (fk) style links. I would appreciate your guidance on how to join all dataframes using an inner join, ensuring that only the matching data based on the pk and fk fields is displayed.
import pandas as pd
from functools import reduce
df1 = pd.DataFrame({
'product_code': ['P001', 'P002', 'P003','P0011', 'P0012', 'P0013','P0021', 'P0022', 'P0023','P0031', 'P0032', 'P0033'],
'Itemname': ['fahim', 'aamir', 'mfatett','2fahim', '2aamir', '2mfatett','32fahim', '32aamir', '32mfatett','4fahim', '4aamir', '4mfatett'],
'stock_quantity': [120, 150, 200,1320, 1450, 2200,1420, 1150, 2400,1520, 1350, 2500,]
})
df2 = pd.DataFrame({
'product_code': ['P001', 'P003', 'P004'],
'store_location': ['New York', 'Chicago', 'Miami'],
'price': [10.50, 25.00, 15.00]
})
df3 = pd.DataFrame({
'area': ['kha', 'had', 'qat'],
'store_location': ['New York', 'Los Angeles', 'Chicago'],
'stock_quantity': [120, 150, 200]
})
df4 = pd.DataFrame({
'area': ['kha', 'had', 'qat'],
'saleperson': ['ahmed', 'muhammad', 'saleem'],
'salesqty': [120, 150, 200]
})
merged_df = pd.merge(df1, df2,df3, df4, on=['product_code','store_location','area'], how='inner')
this code give me error
Please see my code and give me right code
Regard’s