舊金山的租金負擔
在這個練習中,你會檢視舊金山的租金負擔(家庭把收入的 30% 以上用於租金),這裡是全國房價最高的市場之一。
rent DataFrame 包含 7 個收入類別與 8 個「租金占收入比」類別交叉後的家庭數量。對於每一個收入類別,你將使用迴圈計算在該收入類別中,屬於租金負擔家庭的百分比。與各收入類別對應的欄名前綴放在一個清單中:
incomes = ["inc_under_10k", "inc_10k_to_20k", "inc_20k_to_35k", "inc_35k_to_50k",
"inc_50k_to_75k", "inc_75k_to_100k", "inc_over_100k"]
pandas 與 seaborn 已經以慣用別名匯入。
本練習屬於課程
使用 Python 分析美國 Census 資料
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Calculate percentage of rent burdened households
rent_burden = rent[["name"]]
for income in incomes:
rent_burden[income] = 100 * (rent[____] +
rent[____] + rent[____] +
rent[____]) / (rent[income] - rent[income + "_rent_not_computed"])