<jupyter_start><jupyter_text>Upload data set with population estimates per state<jupyter_code>import pandas as pd 
population = pd.read_csv('/content/us_population_abbreviated_state_name.csv')
print(population)<jupyter_output>state  population_estimate state_abbreviation
0                 Alaska               734002                 AK
1                Alabama              4908621                 AL
2               Arkansas              3038999                 AR
3                Arizona              7378494                 AZ
4             California             39937489                 CA
5               Colorado              5845526                 CO
6            Connecticut              3563077                 CT
7   District of Columbia               720687                 DC
8               Delaware               982895                 DE
9                Florida             21992985                 FL
10               Georgia             10736059                 GA
11                Hawaii              1412687                 HI
12                  Iowa              3179849                 IA
13                 Idaho              1826156                 ID
14              Illinois [...]<jupyter_text>Upload data set containing the covid-19 cases and deaths. The csv file should be already cleaned to only include the time period of interest.<jupyter_code>april_covid = pd.read_csv("/content/april_covid_deaths_cases.csv") 
print(april_covid)<jupyter_output>date state  tot_cases  new_case  tot_death  new_death
0     04/01/2020    CO       3342       376         80         11
1     04/02/2020    CO       3728       386         97         17
2     04/03/2020    CO       4173       445        111         14
3     04/04/2020    CO       4565       392        126         15
4     04/05/2020    CO       4950       385        140         14
...          ...   ...        ...       ...        ...        ...
1795  04/26/2020    PW          0         0          0          0
1796  04/27/2020    PW          0         0          0          0
1797  04/28/2020    PW          0         0          0          0
1798  04/29/2020    PW          0         0          0          0
1799  04/30/2020    PW          0         0          0          0

[1800 rows x 6 columns]<jupyter_text>Merge the two csv files so that the population estimates for each state are added to the csv file containing data on the number of covid-19 deaths and cases per state.<jupyter_code>merge_covid = april_covid.merge(population,left_on="state", right_on="state_abbreviation")
(merge_covid)<jupyter_output><empty_output><jupyter_text>Normalise the data by dividing the total cases by the population for each state. This ensures population is taken into account, as otherwise covid-19 cases may be exagerated.<jupyter_code>merge_covid['normalized_tot_cases'] = merge_covid['tot_cases']/merge_covid['population_estimate']*1000
merge_covid<jupyter_output><empty_output><jupyter_text>Normalise the data by dividing the total new cases by the population for each state.<jupyter_code>merge_covid['normalized_new_case'] = merge_covid['new_case']/merge_covid['population_estimate']*1000
merge_covid<jupyter_output><empty_output><jupyter_text>Normalise the data by dividing the total deaths by the population for each state.<jupyter_code>merge_covid['normalized_tot_death'] = merge_covid['tot_death']/merge_covid['population_estimate']*1000
merge_covid<jupyter_output><empty_output><jupyter_text>Normalise the data by dividing the total new deaths by the population for each state.<jupyter_code>merge_covid['normalized_new_death'] = merge_covid['new_death']/merge_covid['population_estimate']*1000
merge_covid<jupyter_output><empty_output><jupyter_text>Remove the columns we do not require.<jupyter_code>merge_covid = merge_covid.drop(['state_x','state_y'], axis=1)
merge_covid<jupyter_output><empty_output><jupyter_text>Export the file as a csv<jupyter_code>merge_covid.to_csv(r'normalised_covid_deaths_cases.csv', index = False)
import matplotlib.pyplot as plt
colorado=merge_covid[merge_covid['state_abbreviation']=="CO"]
colorado
colorado.plot(x='date',y='normalized_tot_cases')

# United States of America Python Dictionary to translate States,
# Districts & Territories to Two-Letter codes and vice versa.
#
# https://gist.github.com/rogerallen/1583593
#
# Dedicated to the public domain.  To the extent possible under law,
# <NAME> has waived all copyright and related or neighboring
# rights to this code.

us_state_abbrev = {
    'Alabama': 'AL',
    'Alaska': 'AK',
    'Arizona': 'AZ',
    'Arkansas': 'AR',
    'California': 'CA',
    'Colorado': 'CO',
    'Connecticut': 'CT',
    'Delaware': 'DE',
    'District of Columbia': 'DC',
    'Florida': 'FL',
    'Georgia': 'GA',
    'Guam': 'GU',
    'Hawaii': 'HI',
    'Idaho': 'ID',
    'Illinois': 'IL',
    'Indiana': 'IN',
    'Iowa': 'IA',
    'Kansas': 'KS',
    'Kentucky': 'KY',
    'Louisiana': 'LA',
    'Maine': 'ME',
    'Maryland': 'MD',
    'Massachusetts': 'MA',
    'Michigan': 'MI',
    'Minnesota': 'MN',
    'Mississippi': 'MS',
    'Missouri': 'MO',
    'Montana': 'MT',
    'Nebraska': 'NE',
    'Nevada': 'NV',
    'New Hampshire': 'NH',
    'New Jersey': 'NJ',
    'New Mexico': 'NM',
    'New York': 'NY',
    'North Carolina': 'NC',
    'North Dakota': 'ND',
    'Northern Mariana Islands':'MP',
    'Ohio': 'OH',
    'Oklahoma': 'OK',
    'Oregon': 'OR',
    'Pennsylvania': 'PA',
    'Rhode Island': 'RI',
    'South Carolina': 'SC',
    'South Dakota': 'SD',
    'Tennessee': 'TN',
    'Texas': 'TX',
    'Utah': 'UT',
    'Vermont': 'VT',
    'Virgin Islands': 'VI',
    'Virginia': 'VA',
    'Washington': 'WA',
    'West Virginia': 'WV',
    'Wisconsin': 'WI',
    'Wyoming': 'WY'
}
state_names=us_state_abbrev.values()
print(state_names)<jupyter_output>dict_values(['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VI', 'VA', 'WA', 'WV', 'WI', 'WY'])<jupyter_text>Adjust the figure size.<jupyter_code>for name in state_names:
  state=merge_covid[merge_covid['state_abbreviation']==name]
  state.plot(x='date',y='normalized_tot_cases')
  plt.figure(figsize=(40, 40))
  plt.savefig('april_covid_{}'.format(name))
  plt.close()<jupyter_output>/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  after removing the cwd from sys.path.
/usr/local/lib/python3.6/dist-packages/pandas/plotting/_matplotlib/core.py:328: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  fig = self.plt.figure(figsize=self.figsize)
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed an[...]
{'fraction_non_alphanumeric': 0.1226815050344462, 'fraction_numerical': 0.0472972972972973, 'mean_word_length': 2.50139146567718, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '172727', 'license': 'MIT', 'n_tokens_mistral': 2654, 'n_tokens_neox': 2379, 'n_words': 645, 'path': 'data_preprocessing/ normalise_covid_deaths_cases_by_population.ipynb', 'repo_name': 'joyjixu/qm2_resources', 'size': '7553'}