-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_processing.py
39 lines (31 loc) · 1.21 KB
/
data_processing.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
28
29
30
31
32
33
34
35
36
37
38
39
import pandas as pd
from datetime import datetime, timedelta
from state_abbreviations import us_state_abbrev
ago = pd.read_csv("ago-us-counties.csv")
today = pd.read_csv("live-us-counties.csv")
def getday(state, county):
r = today.loc[(today['state'] == state) & (today['county'] == county)]
if len(r) == 0:
return None
r = r.iloc[0]
return r['cases'], r['deaths']
def getweek(state, county):
week_ago = str(datetime.today() - timedelta(days=7)).split()[0]
r = ago.loc[(ago['state'] == state) & (ago['county'] == county) & (ago['date'] == week_ago)].iloc[0]
week_ago_cases, week_ago_deaths = r['cases'], r['deaths']
today = getday(state, county)
return today[0] - week_ago_cases, today[1] - week_ago_deaths
def liststates():
return list(today['state'].unique())
def listcounties():
state_abr = []
for state in today['state']:
state_abr.append(us_state_abbrev[state])
return list(today['county'] + " (" + state_abr + ")")
def list_all_counties():
return list(today['county'])
def get_state(county):
r = today.loc[today['county'] == county]
return list(r['state'])
def counties_of_state(state):
return list(today.loc[today['state'] == state]['county'])