General updates
[covid19.git] / uk_deaths.md
index da577be1e206636b31d53ea5bc43f0ef8307a599..e0077b334078753e5cb299385bf8f8a17e188e1e 100644 (file)
@@ -23,6 +23,7 @@ Data from:
 ```python
 import itertools
 import collections
+import json
 import pandas as pd
 import numpy as np
 from scipy.stats import gmean
@@ -91,6 +92,13 @@ dh19i.columns = ['total_2019']
 # dh19i.head()
 ```
 
+```python
+raw_data_2020 = pd.read_csv('uk-deaths-data/publishedweek192020.csv', 
+                       parse_dates=[1], dayfirst=True,
+                      index_col=0,
+                      header=[0, 1])
+```
+
 ```python
 raw_data_2020_i = pd.read_csv('uk-deaths-data/Weekly_Deaths_NI_2020.csv', 
                         parse_dates=[1], dayfirst=True,
@@ -147,13 +155,6 @@ deaths_headlines_s
 
 ```
 
-```python
-raw_data_2020 = pd.read_csv('uk-deaths-data/publishedweek182020.csv', 
-                       parse_dates=[1], dayfirst=True,
-                      index_col=0,
-                      header=[0, 1])
-```
-
 ```python
 # raw_data_2020.head()
 ```
@@ -203,9 +204,9 @@ raw_data_2015 = pd.read_csv('uk-deaths-data/publishedweek2015.csv',
 ```
 
 ```python
-deaths_headlines_e = raw_data_2020.iloc[:, [1]]
+deaths_headlines_e = raw_data_2020.iloc[:, [1]].copy()
 deaths_headlines_e.columns = ['total_2020']
-deaths_headlines_w = raw_data_2020['W92000004']
+deaths_headlines_w = raw_data_2020['W92000004'].copy()
 deaths_headlines_e.columns = ['total_2020']
 deaths_headlines_w.columns = ['total_2020']
 deaths_headlines_e.total_2020 -= deaths_headlines_w.total_2020
@@ -374,10 +375,43 @@ plt.show()
 
 # Excess deaths calculation
 
+```python
+raw_data_2020.loc[12, 'Week ended']
+```
+
+```python
+raw_data_2020.iloc[-1]['Week ended']
+```
+
+```python
+raw_data_2020.loc[12].droplevel(1)['Week ended']
+```
+
+```python
+raw_data_2020.iloc[-1].droplevel(1)['Week ended']
+```
+
 ```python
 (deaths_headlines.loc[12:].total_2020 - deaths_headlines.loc[12:].previous_mean).sum()
 ```
 
+```python
+deaths_headlines.previous_mean.sum()
+```
+
+```python
+excess_death_data = {
+    'start_date': str(raw_data_2020.loc[12].droplevel(1)['Week ended']),
+    'end_date': str(raw_data_2020.iloc[-1].droplevel(1)['Week ended']),
+    'excess_deaths': (deaths_headlines.loc[12:].total_2020 - deaths_headlines.loc[12:].previous_mean).sum()
+}
+
+with open('excess_deaths.json', 'w') as f:
+    json.dump(excess_death_data, f)
+```
+
+# Plots for UK nations
+
 ```python
 # Radar plot code taken from example at https://stackoverflow.com/questions/42878485/getting-matplotlib-radar-plot-with-pandas#