使用 Python 分析美國 Census 資料
Lee Hachadoorian
Asst. Professor of Instruction, Temple University
[B|C]ssnnn[A-I]
B 或 C = 「Base Table」或「Collapsed Table」
| B15002 | C15002[A-I] |
|---|---|
| 無受教育 | 低於高中學歷 |
| 幼稚園到四年級 | 高中畢、GED 或同等 |
| 五、六年級 | 大學肄業或副學士 |
| 七、八年級 | 學士或以上 |
| 九年級 | |
| 等等 | |
A = White aloneB = Black or African American AloneC = American Indian and Alaska Native AloneD = Asian AloneE = Native Hawaiian and Other Pacific Islander AloneF = Some Other Race AloneG = Two or More RacesH = White Alone, Not Hispanic or LatinoI = Hispanic or Latino來源:https://www.census.gov/programs-surveys/acs/guidance/which-data-tool/table-ids-explained.html

寬格式 DataFrame:msa_labor_force
msa male_lf female_lf
0 12060 400843 481425
1 25540 30656 35046
2 26420 231346 268923
3 26900 55943 71036
...
msa_labor_force.columns =
["msa", "male", "female"]
整潔格式 DataFrame:tidy_msa_labor_force
msa sex labor_force
0 12060 male 400843
1 25540 male 30656
2 26420 male 231346
3 26900 male 55943
...
49 12060 female 481425
50 25540 female 35046
51 26420 female 268923
52 26900 female 71036
...
tidy_msa_labor_force = msa_labor_force.melt(id_vars = ["msa"],value_vars = ["male", "female"],var_name = "sex",value_name = "labor_force" )
tidy_msa_labor_force
msa sex labor_force
0 12060 male 400843
1 25540 male 30656
2 26420 male 231346
3 26900 male 55943
...
49 12060 female 481425
50 25540 female 35046
51 26420 female 268923
52 26900 female 71036
...
使用 Python 分析美國 Census 資料