SHARE
TWEET

x

a guest Jul 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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*6 # 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("=============================================================================")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top