```python
import itertools
import collections
+import json
import pandas as pd
import numpy as np
from scipy.stats import gmean
# 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,
```
-```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()
```
```
```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
# 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#