Advertisement
Guest User

Untitled

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