Skip to content

Commit 0381490

Browse files
committed
fixed typos
1 parent cb9bf56 commit 0381490

File tree

3 files changed

+38
-35
lines changed

3 files changed

+38
-35
lines changed

app.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def render_content(tab):
4444
dcc.Dropdown(
4545
id='sex-dropdown',
4646
options=[
47-
{'label': 'Male', 'value': 0},
48-
{'label': 'Female', 'value': 1},
47+
{'label': 'Male', 'value': 1},
48+
{'label': 'Female', 'value': 2},
4949
{'label': 'All', 'value': 3}
5050
],
5151
value=3
@@ -143,7 +143,8 @@ def update_figure(n_clicks, state, sex, race):
143143
color="avg_time",
144144
center={"lat": 37.0902, "lon": -95.7129},
145145
mapbox_style="carto-positron",
146-
range_color=[0, 20],
146+
range_color=[0, 45],
147+
color_continuous_scale="Viridis",
147148
zoom=3)
148149
return fig
149150

src/data/data_process.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,33 @@ def process_acs(self):
5454
]
5555
acs = pl.DataFrame(empty_df).clear()
5656

57-
for file in os.listdir("data/raw"):
58-
if file.startswith("acs"):
59-
original = pl.read_parquet(f"data/raw/{file}")
60-
for sex in [1, 2, 3]:
61-
for race in ["RACAIAN","RACASN","RACBLK","RACNUM","RACWHT","RACSOR","HISP","ALL",]:
62-
df = original
63-
if not sex == 3:
64-
df = df.filter(pl.col("SEX") == sex)
65-
if not race == "ALL":
66-
df = df.filter(pl.col(race) == 1)
67-
df = df.filter(pl.col("JWMNP") > 0)
68-
df = df.select("year", "state", "PUMA", "PWGTP", "JWMNP")
69-
df = df.with_columns(total_time=(pl.col("PWGTP") * pl.col("JWMNP")))
70-
df = df.group_by("year", "state", "PUMA").agg(
71-
pl.col("PWGTP", "total_time").sum())
72-
df = df.select("year","state", "PUMA", "PWGTP",
73-
(pl.col("total_time") / pl.col("PWGTP")).alias("avg_time"),
74-
)
75-
df = df.with_columns(
76-
sex=pl.lit(sex),
77-
race=pl.lit(race),
78-
)
79-
acs = pl.concat([acs, df], how="vertical")
80-
acs.write_parquet("data/interim/acs.parquet")
81-
if self.debug:
82-
print("\033[0;36mINFO: \033[0m" + "Finished processing acs")
57+
if not os.path.exists("data/processed/acs.parquet"):
58+
for file in os.listdir("data/raw"):
59+
if file.startswith("acs"):
60+
original = pl.read_parquet(f"data/raw/{file}")
61+
for sex in [1, 2, 3]:
62+
for race in ["RACAIAN","RACASN","RACBLK","RACNUM","RACWHT","RACSOR","HISP","ALL",]:
63+
df = original
64+
if not sex == 3:
65+
df = df.filter(pl.col("SEX") == sex)
66+
if not race == "ALL":
67+
df = df.filter(pl.col(race) == 1)
68+
df = df.filter(pl.col("JWMNP") > 0)
69+
df = df.select("year", "state", "PUMA", "PWGTP", "JWMNP")
70+
df = df.with_columns(total_time=(pl.col("PWGTP") * pl.col("JWMNP")))
71+
df = df.group_by("year", "state", "PUMA").agg(
72+
pl.col("PWGTP", "total_time").sum())
73+
df = df.select("year","state", "PUMA", "PWGTP",
74+
(pl.col("total_time") / pl.col("PWGTP")).alias("avg_time"),
75+
)
76+
df = df.with_columns(
77+
sex=pl.lit(sex),
78+
race=pl.lit(race),
79+
)
80+
acs = pl.concat([acs, df], how="vertical")
81+
acs.write_parquet("data/processed/acs.parquet")
82+
if self.debug:
83+
print("\033[0;36mINFO: \033[0m" + "Finished processing acs")
8384

8485
def process_roads(self):
8586
roads = gpd.GeoDataFrame(columns=['linear_id', 'year', 'geometry'])

src/visualization/data_graph.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
import geopandas as gpd
33
import pandas as pd
44
import polars as pl
5+
56
class DataGraph:
67
def __init__(self):
78
self.puma = self.load_puma()
89
self.data = self.load_data()
910

1011
def load_puma(self) -> gpd.GeoDataFrame:
1112
puma = gpd.read_file('data/interim/puma.gpkg', engin="pyogrio")
12-
puma["GEOID10"] = puma["GEOID10"].astype(str).str.zfill(6)
13-
return puma[["GEOID10", "geometry"]]
13+
puma["geo_id"] = puma["geo_id"].astype(str).str.zfill(6)
14+
return puma[["geo_id", "geometry"]]
1415

1516
def load_data(self) -> gpd.GeoDataFrame:
1617
df = pd.read_parquet('data/processed/acs.parquet')
17-
df['year'] = pd.to_datetime(df['year'], format='%Y-%m-%d')
18-
df = df[(df["year"] == "2019-01-01")].reset_index(drop=True)
18+
#df['year'] = pd.to_datetime(df['year'], format='%Y-%m-%d')
19+
df = df[(df["year"] == 2019)].reset_index(drop=True)
1920
df = df.drop(columns=["year"]).reset_index(drop=True)
20-
df["GEOID10"] = df["state"].astype(str).str.zfill(2) + df["PUMA"].astype(str).str.zfill(5)
21-
df = df.merge(self.puma, on="GEOID10", how="inner")
21+
df["geo_id"] = df["state"].astype(str).str.zfill(2) + df["PUMA"].astype(str).str.zfill(5)
22+
df = df.merge(self.puma, on="geo_id", how="inner")
2223
return gpd.GeoDataFrame(df, geometry=df["geometry"], crs=3857)
2324

2425
def graph(self, state, sex, race) -> gpd.GeoDataFrame:

0 commit comments

Comments
 (0)