Datasets:
Upload pums.py
Browse files
pums.py
CHANGED
@@ -16,6 +16,50 @@ _ENCODING_DICS = {
|
|
16 |
"50000+.": 1
|
17 |
}
|
18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
DESCRIPTION = "Pums dataset."
|
21 |
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/116/us+census+data+1990"
|
@@ -108,7 +152,7 @@ class Pums(datasets.GeneratorBasedBuilder):
|
|
108 |
]
|
109 |
|
110 |
def _generate_examples(self, filepath: str):
|
111 |
-
data = pandas.read_csv(filepath)
|
112 |
data = self.preprocess(data)
|
113 |
|
114 |
for row_id, row in data.iterrows():
|
@@ -117,6 +161,8 @@ class Pums(datasets.GeneratorBasedBuilder):
|
|
117 |
yield row_id, data_row
|
118 |
|
119 |
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
|
|
|
|
120 |
for feature in _ENCODING_DICS:
|
121 |
encoding_function = partial(self.encode, feature)
|
122 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|
|
|
16 |
"50000+.": 1
|
17 |
}
|
18 |
}
|
19 |
+
_BASE_FEATURE_NAMES = [
|
20 |
+
"age",
|
21 |
+
"class_of_worker",
|
22 |
+
"detailed_industry_recode",
|
23 |
+
"detailed_occupation_recode",
|
24 |
+
"education",
|
25 |
+
"wage_per_hour",
|
26 |
+
"enroll_in_edu_inst_last_wk",
|
27 |
+
"marital_stat",
|
28 |
+
"major_industry_code",
|
29 |
+
"major_occupation_code",
|
30 |
+
"race",
|
31 |
+
"hispanic_origin",
|
32 |
+
"sex",
|
33 |
+
"member_of_a_labor_union",
|
34 |
+
"reason_for_unemployment",
|
35 |
+
"full_or_part_time_employment_stat",
|
36 |
+
"capital_gains",
|
37 |
+
"capital_losses",
|
38 |
+
"dividends_from_stocks",
|
39 |
+
"tax_filer_stat",
|
40 |
+
"region_of_previous_residence",
|
41 |
+
"state_of_previous_residence",
|
42 |
+
"detailed_household_and_family_stat",
|
43 |
+
"detailed_household_summary_in_household",
|
44 |
+
"instance_weight",
|
45 |
+
"migration_code_change_in_msa",
|
46 |
+
"migration_code_change_in_reg",
|
47 |
+
"migration_code_move_within_reg",
|
48 |
+
"live_in_this_house_1_year_ago",
|
49 |
+
"migration_prev_res_in_sunbelt",
|
50 |
+
"num_persons_worked_for_employer",
|
51 |
+
"family_members_under_18",
|
52 |
+
"country_of_birth_father",
|
53 |
+
"country_of_birth_mother",
|
54 |
+
"country_of_birth_self",
|
55 |
+
"citizenship",
|
56 |
+
"own_business_or_self_employed",
|
57 |
+
"fill_inc_questionnaire_for_veteran_admin",
|
58 |
+
"veterans_benefits",
|
59 |
+
"weeks_worked_in_year",
|
60 |
+
"year",
|
61 |
+
"class",
|
62 |
+
]
|
63 |
|
64 |
DESCRIPTION = "Pums dataset."
|
65 |
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/116/us+census+data+1990"
|
|
|
152 |
]
|
153 |
|
154 |
def _generate_examples(self, filepath: str):
|
155 |
+
data = pandas.read_csv(filepath, header=None)
|
156 |
data = self.preprocess(data)
|
157 |
|
158 |
for row_id, row in data.iterrows():
|
|
|
161 |
yield row_id, data_row
|
162 |
|
163 |
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
164 |
+
data.columns = _BASE_FEATURE_NAMES
|
165 |
+
|
166 |
for feature in _ENCODING_DICS:
|
167 |
encoding_function = partial(self.encode, feature)
|
168 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|