-
Notifications
You must be signed in to change notification settings - Fork 0
/
national.py
27 lines (24 loc) · 1.01 KB
/
national.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
import datetime
import pandas as pd
import numpy as np
import requests
from scipy import stats
df = pd.read_csv("covid-tracking.csv",
parse_dates=True, index_col='date')
df = df.sort_index(ascending=True)
df = df.groupby(by=['date']).sum()
rolling = df.rolling(window=7).mean()
export = df.join(rolling, rsuffix="_7day")
export['positivity_7day'] = 100*export['positiveIncrease_7day'] / \
export['totalTestResultsIncrease_7day']
export.to_csv('us_daily.csv')
lastweek = export[['positivity_7day', 'deathIncrease_7day', 'hospitalized_7day',
'positiveIncrease_7day', 'totalTestResultsIncrease_7day']].tail(8)
lastweek['datestr'] = lastweek.index.strftime('%Y-%m-%d')
lastweek = lastweek.reset_index().set_index('datestr')
lastweek.drop(columns='date', inplace=True)
compare = lastweek.iloc[[0, 7]].transpose()
compare['diff'] = compare.iloc[:, 1] - compare.iloc[:, 0]
compare['change_pct'] = 100 * compare.iloc[:, 2] / compare.iloc[:, 0]
compare.to_csv('us_daily_7day_summary.csv')