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 = {}
- 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
- print("=============================================================================")
- print("Display category average stock level")
- print("=============================================================================")
- for key, value in categories.items():
- print("{:<20} :{:>4}".format(key, value))
- print("=============================================================================")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement