Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on Dec 5, 2020
- @author: Viking
- '''
- # "All Sexes"
- # "All Race/Ethnicity Groups"
- # "0-14 Years"
- # "15-19 Years"
- # "80-84 Years"
- # "85+"
- # "All Ages"
- allPeopleCount = 0
- youngPeopleCount = 0
- oldPeopleCount = 0
- allPeopleDeaths= {}
- youngPeopleDeaths = {}
- oldPeopleDeaths = {}
- youngPeopleList = ["0-14 Years", "15-19 Years", "20-24 Years", "25-29 Years", "30-34 Years",
- "35-39 Years", "40-44 Years", "45-49 Years", "50-54 Years" , "55-59 Years",
- "60-64 Years" ]
- oldPeopleList = ["65-69 Years", "70-74 Years", "75-79 Years", "80-84 Years", "85+"]
- import csv
- with open('./AH_Excess_Deaths_by_Sex__Age__and_Race.csv') as csv_file:
- csv_reader = csv.reader(csv_file, delimiter=',')
- line_count = 0
- for row in csv_reader:
- if line_count == 0:
- print(f'Column names are {", ".join(row)}')
- print(row[5])
- line_count += 1
- if row[5] == "All Race/Ethnicity Groups":
- if row[6] == "All Sexes":
- yearWeek = ":".join([row[2], row[3]])
- if row[7] == "All Ages":
- allPeopleCount += 1
- allPeopleDeaths[yearWeek] = int(row[10])
- if row[7] in youngPeopleList:
- youngPeopleCount += 1
- if yearWeek in youngPeopleDeaths:
- youngPeopleDeaths[yearWeek] = int(row[10]) + youngPeopleDeaths[yearWeek]
- else:
- youngPeopleDeaths[yearWeek] = int(row[10])
- if row[7] in oldPeopleList:
- oldPeopleCount += 1
- if yearWeek in oldPeopleDeaths:
- oldPeopleDeaths[yearWeek] = int(row[10]) + oldPeopleDeaths[yearWeek]
- else:
- oldPeopleDeaths[yearWeek] = int(row[10])
- else:
- #print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
- line_count += 1
- print(f'Processed {line_count} lines.')
- print(f'Added {allPeopleCount} Key/Value pairs to allPeopleCount.')
- print(f'Added {youngPeopleCount} Key/Value pairs to youngPeopleCount.')
- print(f'Added {oldPeopleCount} Key/Value pairs to oldPeopleCount.')
- x1 = list(range(1,52))
- x2 = x3 = x4 = x5 = x1
- x20 = list(range(1,44))
- old2015 = []
- young2015 = []
- key1 = ''
- x = 0
- while x < len(x1):
- key1 = '2015' + ':' + str(x+1)
- old2015.append(int(oldPeopleDeaths[key1]))
- young2015.append(int(youngPeopleDeaths[key1]))
- x += 1
- old2016 = []
- young2016 = []
- x = 0
- while x < len(x2):
- key1 = '2016' + ':' + str(x+1)
- old2016.append(int(oldPeopleDeaths[key1]))
- young2016.append(int(youngPeopleDeaths[key1]))
- x += 1
- old2017 = []
- young2017 = []
- x = 0
- while x < len(x3):
- key1 = '2017' + ':' + str(x+1)
- old2017.append(int(oldPeopleDeaths[key1]))
- young2017.append(int(youngPeopleDeaths[key1]))
- x += 1
- old2018 = []
- young2018 = []
- x = 0
- while x < len(x4):
- key1 = '2018' + ':' + str(x+1)
- old2018.append(int(oldPeopleDeaths[key1]))
- young2018.append(int(youngPeopleDeaths[key1]))
- x += 1
- old2019 = []
- young2019 = []
- x = 0
- while x < len(x5):
- key1 = '2019' + ':' + str(x+1)
- old2019.append(int(oldPeopleDeaths[key1]))
- young2019.append(int(youngPeopleDeaths[key1]))
- x += 1
- old2020 = []
- young2020 = []
- x=0
- key1 = ''
- while x < len(x20):
- key1 = '2020' + ':' + str(x+1)
- print(key1)
- print(oldPeopleDeaths[key1])
- print(int(oldPeopleDeaths[key1]))
- print(youngPeopleDeaths[key1])
- print(int(youngPeopleDeaths[key1]))
- old2020.append(int(oldPeopleDeaths[key1]))
- young2020.append(int(youngPeopleDeaths[key1]))
- x += 1
- print(len(x20))
- print(len(old2020))
- import numpy as np
- import matplotlib.pyplot as plt
- fig, axs = plt.subplots()
- axs.plot(x1, old2015, x2,old2016, x3,old2017, x4,old2018, x5,old2019, x20,old2020)
- axs.set_xlim(0, 53)
- #axs[0].set_ylim(0, 10000)
- axs.set_xlabel('Week Number')
- axs.set_ylabel('Weekly old deaths')
- axs.grid(True)
- fig, axs = plt.subplots()
- axs.plot(x1, young2015, x2,young2016, x3,young2017, x4,young2018, x5,young2019, x20,young2020)
- axs.set_xlim(0, 53)
- #axs[0].set_ylim(0, 10000)
- axs.set_xlabel('Week Number')
- axs.set_ylabel('Weekly young deaths')
- axs.grid(True)
- #cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
- #axs[1].set_ylabel('WD2')
- fig.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment