Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv # import csv file
- filePath1 = "category.csv"
- filePath2 = "data.csv"
- categories = {}
- stock_level = {}
- with open(filePath1) as csvfile: # open category file
- reader = csv.DictReader(csvfile) # dictread file
- for row in reader: # Create a dictionary map of all the categories, and initialise count to 0
- categories[row['CATEGORY']] = 0
- with open(filePath2) as csvfile: # open data file
- reader = csv.DictReader(csvfile) # dictread file
- for row in reader:
- categories[row['CATEGORY']] += 1 # For every item in data file, increment the count of the category
- stock_level[row['STOCK LEVEL']] = 0
- print("=============================================================================")
- print("Display category average stock level")
- print("=============================================================================")
- for key, value in categories.items():
- for stock_value in stock_level.items():
- print("{0} :{1}".format(key, stock_value))
- print("=============================================================================")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement