-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
66 lines (53 loc) · 1.98 KB
/
utils.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
65
66
import logging
import os
import pandas as pd
from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
def write_output_file(df, filename, sheet_name="codefornola cleaned"):
if filename.startswith("data") and not os.path.exists("data"):
logging.debug("Creating data directory")
os.makedirs("data")
logging.debug(f"Writing sheet '{sheet_name}' into '{filename}'")
df.to_excel(filename)
def get_lat(zipcode):
if pd.isnull(zipcode):
return None
else:
lat = search.by_zipcode(int(zipcode)).lat
return lat if lat else None
def get_lng(zipcode):
if pd.isnull(zipcode):
return None
else:
lng = search.by_zipcode(int(zipcode)).lng
return lng if lng else None
def explode_needs(df, need_column):
logging.debug(f"exploding needs into {need_column}")
df["tmp_needs"] = df[need_column].astype(str).str.split(";")
df = df.explode("tmp_needs")
df.drop(columns=[need_column], inplace=True)
df.rename(columns={"tmp_needs": need_column}, inplace=True)
return df
def remove_first_rows(df):
columns = df.iloc[1].values.tolist()
df = df.iloc[2:]
df.columns = columns
return df
replacements = {
"†": "",
"Employment": "Employment Services",
"Food": "Food/Meals",
"Food/Meal": "Food/Meals",
"I'm Sick (what next?)": "I'm Sick (What's Next?)",
"I'm Sick (Whats Next?)": "I'm Sick (What's Next?)",
"Income support/assistance": "Income Support/Assistance",
"information only call": "",
"Inquires about Health Complications / Concerns": "Inquires about Health Complications",
"International Travel Concerns": "International / General Travel Concerns",
"Legal Consumer": "Legal Assistance",
"Other - Interpersonal": "Other",
"Other (PLEASE Specify Caller Need in Call Notes)": "Other",
"Other (please specify caller need in call notes)": "Other",
"other 2-1-1 referral": "Other",
"Unemployment": "Unemployment Benefits",
}