-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
64 lines (53 loc) · 1.83 KB
/
data.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pandas as pd
conditions = ["confirmed", "deaths", "recovered"]
daily_df = pd.read_csv("data/daily_report.csv")
totals_df = (
daily_df[["Confirmed", "Deaths", "Recovered"]].sum().reset_index(name="count")
)
totals_df = totals_df.rename(columns={"index": "condition"})
countries_df = daily_df[["Country_Region", "Confirmed", "Deaths", "Recovered"]]
countries_df = (
countries_df.groupby("Country_Region")
.sum()
.sort_values(by="Confirmed", ascending=False)
.reset_index()
)
dropdown_options = countries_df.sort_values("Country_Region").reset_index()
dropdown_options = dropdown_options["Country_Region"]
def make_country_df(country):
def make_df(condition):
df = pd.read_csv(f"data/time_{condition}.csv")
df = df.loc[df["Country/Region"] == country]
df = (
df.drop(columns=["Province/State", "Country/Region", "Lat", "Long"])
.sum()
.reset_index(name=condition)
)
df = df.rename(columns={"index": "date"})
return df
final_df = None
for condition in conditions:
condition_df = make_df(condition)
if final_df is None:
final_df = condition_df
else:
final_df = final_df.merge(condition_df)
return final_df
def make_global_df():
def make_df(condition):
df = pd.read_csv(f"data/time_{condition}.csv")
df = (
df.drop(["Province/State", "Country/Region", "Lat", "Long"], axis=1)
.sum()
.reset_index(name=condition)
)
df = df.rename(columns={"index": "date"})
return df
final_df = None
for condition in conditions:
condition_df = make_df(condition)
if final_df is None:
final_df = condition_df
else:
final_df = final_df.merge(condition_df)
return final_df