I am trying to merge two csv files with a common column and write it to a new file. For example product.csv table will have columns
product_id name
1 Handwash
2 Soap
and subproduct.csv will have columns
product_id subproduct_name volume
1 Dettol 20
1 Lifebuoy 50
2 Lux 100
The output sales.csv file should be like:
product_id name subproduct_name volume
1 Handwash Dettol 20
1 Handwash Lifebuoy 50
2 Soap Lux 100
I have tried to create two dictionaries:
with open('product.csv', 'r') as f:
r = csv.reader(f)
dict1 = {row[0]: row[1:] for row in r}
with open('subproduct.csv', 'r') as f:
r = csv.reader(f)
dict2 = {row[0]: row[1:] for row in r}