-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_lib.py
54 lines (38 loc) · 1.15 KB
/
func_lib.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
from simpledbf import Dbf5
import config as cfg
import pandas as pd
import streamlit as st
def get_county_key(df, state):
return df[df.state == state].county.unique()
def get_state_key(df):
return sorted(df.state.unique())
def get_fips():
dbf = Dbf5(cfg.dbf)
fips_df = dbf.to_dataframe()
fips_df["FIPS"] = fips_df["FIPS"].astype(float)
return fips_df.loc[:, ["FIPS", "LON", "LAT"]]
def df_left_merge(left_df, right_df):
return left_df.merge(right_df, left_on="fips", right_on="FIPS", how="left")
def df_clean(ff):
ff1 = ff.rename(columns={"LON": "lon", "LAT": "lat"})
return ff1.dropna()
@st.cache
def get_coord(df):
df1 = get_fips()
merged_df = df_left_merge(df, df1)
clean_df = df_clean(merged_df)
return clean_df
@st.cache
def get_data():
df = pd.read_csv(cfg.db)
df["date"] = pd.to_datetime(df["date"])
return df
def filter_data_by_county_state(df, co, st):
if (co == "All") & (st == "All"):
return df
elif co == "All":
return df[df.state == st]
elif st == "All":
return df[df.county == co]
else:
return df[(df.state == st) & (df.county == co)]