Guest User

Untitled

a guest
Dec 6th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.47 KB | None | 0 0
  1. '''
  2. Created on Dec 5, 2020
  3.  
  4. @author: Viking
  5. '''
  6. # "All Sexes"
  7. # "All Race/Ethnicity Groups"
  8. # "0-14 Years"
  9. # "15-19 Years"
  10. # "80-84 Years"
  11. # "85+"
  12. # "All Ages"
  13. allPeopleCount = 0
  14. youngPeopleCount = 0
  15. oldPeopleCount = 0
  16. allPeopleDeaths= {}
  17. youngPeopleDeaths = {}
  18. oldPeopleDeaths = {}
  19. youngPeopleList = ["0-14 Years", "15-19 Years", "20-24 Years", "25-29 Years", "30-34 Years",  
  20.                    "35-39 Years", "40-44 Years",  "45-49 Years", "50-54 Years" , "55-59 Years",
  21.                    "60-64 Years" ]
  22. oldPeopleList = ["65-69 Years", "70-74 Years", "75-79 Years", "80-84 Years", "85+"]
  23. import csv
  24. with open('./AH_Excess_Deaths_by_Sex__Age__and_Race.csv') as csv_file:
  25.     csv_reader = csv.reader(csv_file, delimiter=',')
  26.     line_count = 0
  27.     for row in csv_reader:
  28.         if line_count == 0:
  29.             print(f'Column names are {", ".join(row)}')
  30.             print(row[5])
  31.             line_count += 1
  32.         if row[5] == "All Race/Ethnicity Groups":
  33.             if row[6] == "All Sexes":
  34.                 yearWeek = ":".join([row[2], row[3]])
  35.                 if row[7] == "All Ages":
  36.                     allPeopleCount += 1
  37.                     allPeopleDeaths[yearWeek] = int(row[10])
  38.                 if row[7] in youngPeopleList:
  39.                     youngPeopleCount += 1
  40.                     if yearWeek in youngPeopleDeaths:
  41.                         youngPeopleDeaths[yearWeek] = int(row[10]) + youngPeopleDeaths[yearWeek]
  42.                     else:
  43.                         youngPeopleDeaths[yearWeek] = int(row[10])
  44.                 if row[7] in oldPeopleList:
  45.                     oldPeopleCount += 1
  46.                     if yearWeek in oldPeopleDeaths:
  47.                         oldPeopleDeaths[yearWeek] = int(row[10]) + oldPeopleDeaths[yearWeek]
  48.                     else:
  49.                         oldPeopleDeaths[yearWeek] = int(row[10])
  50.                
  51.         else:
  52.             #print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
  53.             line_count += 1
  54.     print(f'Processed {line_count} lines.')
  55.     print(f'Added {allPeopleCount} Key/Value pairs to allPeopleCount.')
  56.     print(f'Added {youngPeopleCount} Key/Value pairs to youngPeopleCount.')
  57. print(f'Added {oldPeopleCount} Key/Value pairs to oldPeopleCount.')
  58. x1 = list(range(1,52))
  59. x2 = x3 = x4 = x5 = x1
  60. x20 = list(range(1,44))
  61.  
  62. old2015 = []
  63. young2015 = []
  64. key1 = ''
  65. x = 0
  66. while x < len(x1):
  67.     key1 = '2015' + ':' + str(x+1)
  68.     old2015.append(int(oldPeopleDeaths[key1]))
  69.     young2015.append(int(youngPeopleDeaths[key1]))
  70.     x += 1
  71.  
  72. old2016 = []
  73. young2016 = []
  74. x = 0
  75. while x < len(x2):
  76.     key1 = '2016' + ':' + str(x+1)
  77.     old2016.append(int(oldPeopleDeaths[key1]))
  78.     young2016.append(int(youngPeopleDeaths[key1]))
  79.     x += 1
  80.  
  81. old2017 = []
  82. young2017 = []
  83. x = 0
  84. while x < len(x3):
  85.     key1 = '2017' + ':' + str(x+1)
  86.     old2017.append(int(oldPeopleDeaths[key1]))
  87.     young2017.append(int(youngPeopleDeaths[key1]))
  88.     x += 1
  89.  
  90. old2018 = []
  91. young2018 = []
  92. x = 0
  93. while x < len(x4):
  94.     key1 = '2018' + ':' + str(x+1)
  95.     old2018.append(int(oldPeopleDeaths[key1]))
  96.     young2018.append(int(youngPeopleDeaths[key1]))
  97.     x += 1
  98.  
  99. old2019 = []
  100. young2019 = []
  101. x = 0
  102. while x < len(x5):
  103.     key1 = '2019' + ':' + str(x+1)
  104.     old2019.append(int(oldPeopleDeaths[key1]))
  105.     young2019.append(int(youngPeopleDeaths[key1]))
  106.     x += 1
  107.  
  108.  
  109. old2020 = []
  110. young2020 = []
  111. x=0
  112. key1 = ''
  113. while x < len(x20):
  114.     key1 = '2020' + ':' +  str(x+1)
  115.     print(key1)
  116.     print(oldPeopleDeaths[key1])
  117.     print(int(oldPeopleDeaths[key1]))
  118.     print(youngPeopleDeaths[key1])
  119.     print(int(youngPeopleDeaths[key1]))
  120.    
  121.     old2020.append(int(oldPeopleDeaths[key1]))
  122.     young2020.append(int(youngPeopleDeaths[key1]))
  123.     x += 1
  124.  
  125. print(len(x20))
  126. print(len(old2020))
  127.  
  128. import numpy as np
  129. import matplotlib.pyplot as plt  
  130. fig, axs = plt.subplots()
  131. axs.plot(x1, old2015, x2,old2016, x3,old2017, x4,old2018, x5,old2019, x20,old2020)
  132. axs.set_xlim(0, 53)
  133. #axs[0].set_ylim(0, 10000)
  134. axs.set_xlabel('Week Number')
  135. axs.set_ylabel('Weekly old deaths')
  136. axs.grid(True)
  137.  
  138. fig, axs = plt.subplots()
  139. axs.plot(x1, young2015, x2,young2016, x3,young2017, x4,young2018, x5,young2019, x20,young2020)
  140. axs.set_xlim(0, 53)
  141. #axs[0].set_ylim(0, 10000)
  142. axs.set_xlabel('Week Number')
  143. axs.set_ylabel('Weekly young deaths')
  144. axs.grid(True)
  145.  
  146. #cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
  147. #axs[1].set_ylabel('WD2')
  148. fig.tight_layout()
  149. plt.show()    
  150.    
  151.    
  152.    
  153.    
  154.    
Advertisement
Add Comment
Please, Sign In to add comment