Use pd.cut() for income_cat
parent
e8ed65eac6
commit
5f6be6fa6f
|
@ -338,10 +338,9 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Divide by 1.5 to limit the number of income categories\n",
|
||||
"housing[\"income_cat\"] = np.ceil(housing[\"median_income\"] / 1.5)\n",
|
||||
"# Label those above 5 as 5\n",
|
||||
"housing[\"income_cat\"].where(housing[\"income_cat\"] < 5, 5.0, inplace=True)"
|
||||
"housing[\"income_cat\"] = pd.cut(housing[\"median_income\"],\n",
|
||||
" bins=[0., 1.5, 3.0, 4.5, 6., np.inf],\n",
|
||||
" labels=[1, 2, 3, 4, 5])"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue