Advertisement
Guest User

New Paste

a guest
Jul 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import csv # import csv file
  2.  
  3. filePath1 = "category.csv"
  4. filePath2 = "data.csv"
  5.  
  6. categories = {}
  7. with open(filePath1) as csvfile: # open category file
  8. reader = csv.DictReader(csvfile) # dictread file
  9. for row in reader: # Create a dictionary map of all the categories, and initialise count to 0
  10. categories[row["CATEGORY"]] = 0
  11.  
  12. with open(filePath2) as csvfile: # open data file
  13. reader = csv.DictReader(csvfile) # dictread file
  14. for row in reader:
  15. categories[row["CATEGORY"]] += 1 # For every item in data file, increment the count of the category
  16.  
  17. print("=============================================================================")
  18. print("Display category average stock level")
  19. print("=============================================================================")
  20. for key, value in categories.items():
  21. print("{:<20} :{:>4}".format(key, value))
  22. print("=============================================================================")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement