Skip to content

Commit

Permalink
pandas fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sid-kap committed Sep 24, 2023
1 parent 70d4685 commit 2e7288f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion python/housing_data/california_hcd_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load_california_hcd_data(
# BPS doesn't include mobile homes, so we shouldn't include them here either
df = df[df["UNIT_CAT_DESC"] != "Mobile Home Unit"].copy()

df["units"] = df[BUILDING_PERMIT_COLUMNS].sum(axis="columns")
df["units"] = df[BUILDING_PERMIT_COLUMNS].sum(axis="columns", numeric_only=True)
df = df[
(df["units"] > 0)
# Exclude rows with a certificate of occupancy, because it's very unlikely
Expand Down
4 changes: 2 additions & 2 deletions python/housing_data/canada_bper.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def aggregate_to_metros(df: pd.DataFrame) -> pd.DataFrame:
df = (
df.drop(columns=["place_name", "province_abbr", "province"])
.groupby(["metro", "year", "metro_province_abbr"], as_index=False)
.sum()
.sum(numeric_only=True)
)
add_per_capita_columns(df, [DataSource.CANADA])

Expand All @@ -226,7 +226,7 @@ def aggregate_to_states(df: pd.DataFrame) -> pd.DataFrame:
df = (
df.drop(columns=["path_1", "path_2"])
.groupby(["province", "year"], as_index=False)
.sum()
.sum(numeric_only=True)
)
add_per_capita_columns(df, [DataSource.CANADA])

Expand Down
2 changes: 1 addition & 1 deletion python/housing_data/county_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_county_populations_1980s(data_path: Optional[Path]) -> pd.DataFrame:
df = (
df.dropna(subset=["year"])
.groupby(["year", "combined_fips"])
.sum()
.sum(numeric_only=True)
.sum(axis=1)
.rename("population")
.reset_index()
Expand Down
2 changes: 1 addition & 1 deletion python/housing_data/place_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_place_populations_1990s(data_path: Optional[Path]) -> pd.DataFrame:
["place", "state_abbr", "state_fips", "place_fips", "place_or_county_code"],
dropna=False,
)
.sum()
.sum(numeric_only=True)
.reset_index()
)

Expand Down
6 changes: 3 additions & 3 deletions python/housing_data/state_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_state_populations_1990s(data_path: Optional[Path]) -> pd.DataFrame:
]
)
.groupby(["year", "state"])
.sum()
.sum(numeric_only=True)
.reset_index()
)

Expand Down Expand Up @@ -263,13 +263,13 @@ def get_state_population_estimates(data_path: Optional[Path]) -> pd.DataFrame:
divisions_df = (
states_df.assign(state=states_df["state"].map(STATE_TO_DIVISION))
.groupby(["state", "year"])
.sum()
.sum(numeric_only=True)
.reset_index()
)
regions_df = (
states_df.assign(state=states_df["state"].map(STATE_TO_REGION))
.groupby(["state", "year"])
.sum()
.sum(numeric_only=True)
.reset_index()
)

Expand Down

0 comments on commit 2e7288f

Please sign in to comment.