Skip to content

Commit 0ebb815

Browse files
committed
clean small_example data and add randomly generated values to industry and occupation
1 parent aac079d commit 0ebb815

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

-1.77 MB
Binary file not shown.

demos/models/income.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def hh_head_edu_bin3(households, persons):
8686

8787
# Job industry variables
8888
# TODO: This column should be implemented more rigorously based on actual job industry data rather than random assignment
89-
@orca.column("households", cache=True, cache_scope="step")
90-
def job_industry(households):
91-
return pd.Series(np.random.choice([1, 2, 3, 4]), index=households.index)
89+
# @orca.column("households", cache=True, cache_scope="step")
90+
# def job_industry(households):
91+
# return pd.Series(np.random.choice([1, 2, 3, 4]), index=households.index)
9292

9393
@orca.column("households")
9494
def job_industry_bin1(households): # First quartile
@@ -107,9 +107,9 @@ def job_industry_bin4(households):
107107
return (households["job_industry"] == 4).astype(int)
108108

109109
# TODO: This column should be implemented more rigorously based on actual job industry data rather than random assignment
110-
@orca.column("households", cache=True, cache_scope="step")
111-
def job_occupation(households):
112-
return pd.Series(np.random.choice([1, 2, 3, 4]), index=households.index)
110+
# @orca.column("households", cache=True, cache_scope="step")
111+
# def job_occupation(households):
112+
# return pd.Series(np.random.choice([1, 2, 3, 4]), index=households.index)
113113

114114
@orca.column("households")
115115
def job_occupation_bin1(households): # First quartile

scripts/clean_columns.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
if __name__ == "__main__":
2+
import argparse
3+
import pandas as pd
4+
import numpy as np
5+
6+
# argument parser to receive the input file path and the output file path
7+
parser = argparse.ArgumentParser(description="Clean columns in H5 file")
8+
parser.add_argument("--input", required=True, help="Input H5 file path")
9+
parser.add_argument("--output", required=True, help="Output H5 file path")
10+
args = parser.parse_args()
11+
12+
# Read H5 file and filter a list of hardn0coded columns
13+
persons_df = pd.read_hdf(args.input, key="persons")
14+
persons_required_columns = [
15+
"age",
16+
"sex",
17+
"person_sex",
18+
"edu",
19+
"student",
20+
"worker",
21+
"earning",
22+
"MAR",
23+
"relate",
24+
"race_id",
25+
"hispanic",
26+
"household_id",
27+
]
28+
persons_df = persons_df[persons_required_columns]
29+
# Save the filtered DataFrame to a new H5 file
30+
persons_df.to_hdf(args.output, key="persons", mode="w")
31+
32+
# Do the same for the "households" table
33+
households_df = pd.read_hdf(args.input, key="households")
34+
households_required_columns = [
35+
"income",
36+
"lcm_county_id",
37+
]
38+
households_df = households_df[households_required_columns]
39+
40+
# Add random values between 1 and 4 to the "job_industry" column and "job_occupation" column
41+
households_df["job_industry"] = pd.Series(
42+
np.random.choice([1, 2, 3, 4], size=len(households_df)), index=households_df.index
43+
)
44+
households_df["job_occupation"] = pd.Series(
45+
np.random.choice([1, 2, 3, 4], size=len(households_df)), index=households_df.index
46+
)
47+
households_df.to_hdf(args.output, key="households", mode="a")

0 commit comments

Comments
 (0)