Skip to content

Commit 6adc598

Browse files
committed
Add lesson 7 - activity 1
1 parent b7df9c5 commit 6adc598

File tree

4 files changed

+699
-0
lines changed

4 files changed

+699
-0
lines changed
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# New York City\n",
8+
"In this activity we will visualize data about New York City (NYC) and compare it with the state of New York and the United States (US). The American Community Survey (ACS) Public Use Microdata Sample (PUMS) dataset (1-year estimate from 2017) from https://www.census.gov/programs-surveys/acs/technical-documentation/pums/documentation.2017.html is used.\n",
9+
"\n",
10+
"Download the following datasets and place the extracted csv-file in the data subdirectory:\n",
11+
"https://www2.census.gov/programs-surveys/acs/data/pums/2017/1-Year/csv_pny.zip\n",
12+
"https://www2.census.gov/programs-surveys/acs/data/pums/2017/1-Year/csv_hny.zip\n",
13+
"\n",
14+
"In this activity the datasets 'New York Population Records' (./data/pny.csv) and 'New York Housing Unit Records' (./data/hny.csv) are used. The first dataset contains information about the New York population, and the second dataset contains information about housing units. The dataset contains data for about 1% of the population and housing units. Due to the extensive amount of data we do not provide the datasets for the whole US, instead we provide the required information related to the US if necessary. The pdf 'PUMS_Data_Dictionary_2017.pdf' gives an overview and description of all variables. A further description of the codes can be found in 'ACSPUMS2017CodeLists.xls'."
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"Use the following code cell to define all required import statements."
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"# Import statements\n"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"Use pandas to read both csv-files located in the subdirectory 'data'."
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": null,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": []
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"metadata": {},
50+
"source": [
51+
"Use the given PUMA (public use microdata area code based on 2010 Census definition which are areas with populations of 100,000 or more) ranges to further divide the dataset into NYC districts (Bronx, Manhatten, Staten Island, Brooklyn, and Queens)."
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"# PUMA ranges\n",
61+
"bronx = [3701, 3710]\n",
62+
"manhatten = [3801, 3810]\n",
63+
"staten_island = [3901, 3903]\n",
64+
"brooklyn = [4001, 4017]\n",
65+
"queens = [4101, 4114]\n",
66+
"nyc = [bronx[0], queens[1]]\n",
67+
"\n"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"metadata": {},
73+
"source": [
74+
"In the dataset each sample has a certain weight that reflects the weight for the total dataset. Therefore we cannot simply calculate the median. Use the given weighted_median function in the following to compute the median."
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"# Function for a 'weighted' median\n",
84+
"def weighted_frequency(values, weights):\n",
85+
" weighted_values = []\n",
86+
" for value, weight in zip(values, weights):\n",
87+
" weighted_values.extend(np.repeat(value, weight))\n",
88+
" return weighted_values\n",
89+
"\n",
90+
"def weighted_median(values, weights):\n",
91+
" return np.median(weighted_frequency(values, weights))"
92+
]
93+
},
94+
{
95+
"cell_type": "markdown",
96+
"metadata": {},
97+
"source": [
98+
"## Wages\n",
99+
"In this subtask we will create a plot containing multiple subplots which visualize information with regards to NYC wages.\n",
100+
"- Visualize the median household income for the US, New York, New York City, and its districts.\n",
101+
"- Visualize the average wage by gender for the given occupation categories for the population of NYC.\n",
102+
"- Visualize the wage distribution for New York and NYC. Use the following yearly wage intervals: 10k steps between 0 and 100k, 50k steps between 100k and 200k, and >200k"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"# Data wrangling for median housing income\n"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"# Data wrangling for wage by gender for different occupation categories\n",
121+
"occ_categories = ['Management,\\nBusiness,\\nScience,\\nand Arts\\nOccupations', 'Service\\nOccupations',\n",
122+
" 'Sales and\\nOffice\\nOccupations', 'Natural Resources,\\nConstruction,\\nand Maintenance\\nOccupations',\n",
123+
" 'Production,\\nTransportation,\\nand Material Moving\\nOccupations']\n",
124+
"occ_ranges = {'Management, Business, Science, and Arts Occupations': [10, 3540], 'Service Occupations': [3600, 4650], \n",
125+
" 'Sales and Office Occupations': [4700, 5940], 'Natural Resources, Construction, and Maintenance Occupations': [6000, 7630], \n",
126+
" 'Production, Transportation, and Material Moving Occupations': [7700, 9750]}\n",
127+
"\n"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"# Data wrangling for wage distribution\n"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": null,
142+
"metadata": {},
143+
"outputs": [],
144+
"source": [
145+
"# Create figure with four subplots\n",
146+
"\n",
147+
"\n",
148+
"# Median household income in the US\n",
149+
"us_income_median = 60336\n",
150+
"\n",
151+
"# Median household income\n",
152+
"\n",
153+
"\n",
154+
"# Wage by gender in common jobs\n",
155+
"\n",
156+
"\n",
157+
"# Wage distribution\n",
158+
"\n",
159+
"\n",
160+
"# Overall figure\n"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"metadata": {},
166+
"source": [
167+
"## Occupations\n",
168+
"Use a tree map to visualize the percentage for the given occupation subcategories for the population of NYC."
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": null,
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"# Data wrangling for occupations\n",
178+
"occ_subcategories = {'Management,\\nBusiness,\\nand Financial': [10, 950],\n",
179+
" 'Computer, Engineering,\\nand Science': [1000, 1965],\n",
180+
" 'Education,\\nLegal,\\nCommunity Service,\\nArts,\\nand Media': [2000, 2960],\n",
181+
" 'Healthcare\\nPractitioners\\nand\\nTechnical': [3000, 3540],\n",
182+
" 'Service': [3600, 4650],\n",
183+
" 'Sales\\nand Related': [4700, 4965],\n",
184+
" 'Office\\nand Administrative\\nSupport': [5000, 5940],\n",
185+
" '': [6000, 6130],\n",
186+
" 'Construction\\nand Extraction': [6200, 6940],\n",
187+
" 'Installation,\\nMaintenance,\\nand Repair': [7000, 7630],\n",
188+
" 'Production': [7700, 8965],\n",
189+
" 'Transportation\\nand Material\\nMoving': [9000, 9750]}\n",
190+
"\n"
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"execution_count": null,
196+
"metadata": {},
197+
"outputs": [],
198+
"source": [
199+
"# Visualization of tree map\n"
200+
]
201+
},
202+
{
203+
"cell_type": "markdown",
204+
"metadata": {},
205+
"source": [
206+
"## Correlation\n"
207+
]
208+
},
209+
{
210+
"cell_type": "markdown",
211+
"metadata": {},
212+
"source": [
213+
"Use a heatmap to show the correlation between difficulties (self-care difficulty, hearing difficulty, vision, difficulty, independent living difficulty, ambulatory difficulty, veteran service connected disability, and cognitive difficulty) and age groups (<5, 5-11, 12-14, 15-17, 18-24, 25-34, 35-44, 45-54, 55-64, 65-74, 75+) in New York City."
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"execution_count": null,
219+
"metadata": {},
220+
"outputs": [],
221+
"source": [
222+
"# Data wrangling for New York City population difficulties\n"
223+
]
224+
},
225+
{
226+
"cell_type": "code",
227+
"execution_count": null,
228+
"metadata": {},
229+
"outputs": [],
230+
"source": [
231+
"# Heatmap\n"
232+
]
233+
},
234+
{
235+
"cell_type": "code",
236+
"execution_count": null,
237+
"metadata": {},
238+
"outputs": [],
239+
"source": []
240+
}
241+
],
242+
"metadata": {
243+
"kernelspec": {
244+
"display_name": "Python 3",
245+
"language": "python",
246+
"name": "python3"
247+
},
248+
"language_info": {
249+
"codemirror_mode": {
250+
"name": "ipython",
251+
"version": 3
252+
},
253+
"file_extension": ".py",
254+
"mimetype": "text/x-python",
255+
"name": "python",
256+
"nbconvert_exporter": "python",
257+
"pygments_lexer": "ipython3",
258+
"version": "3.6.6"
259+
}
260+
},
261+
"nbformat": 4,
262+
"nbformat_minor": 2
263+
}

0 commit comments

Comments
 (0)