Skip to content

Commit 5a5015d

Browse files
committed
update 3d-exercise
Improved Readability
1 parent 97a4e22 commit 5a5015d

File tree

3 files changed

+570
-6
lines changed

3 files changed

+570
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"ExecuteTime": {
8+
"end_time": "2020-04-23T18:44:33.442796Z",
9+
"start_time": "2020-04-23T18:44:32.388132Z"
10+
}
11+
},
12+
"outputs": [],
13+
"source": [
14+
"# import geopandas and matplotlib\n",
15+
"import geopandas as gpd\n",
16+
"import matplotlib.pyplot as plt"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {
23+
"ExecuteTime": {
24+
"end_time": "2020-04-23T18:44:33.532177Z",
25+
"start_time": "2020-04-23T18:44:33.495683Z"
26+
}
27+
},
28+
"outputs": [],
29+
"source": [
30+
"# countries data\n",
31+
"world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))"
32+
]
33+
},
34+
{
35+
"cell_type": "markdown",
36+
"metadata": {},
37+
"source": [
38+
"**Print the top 5 rows of world dataframe.**"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {
45+
"ExecuteTime": {
46+
"end_time": "2020-04-23T18:42:59.340723Z",
47+
"start_time": "2020-04-23T18:42:59.319452Z"
48+
}
49+
},
50+
"outputs": [],
51+
"source": []
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {},
56+
"source": [
57+
"**Remove continents which have only one country in dataframe.**\n"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 1,
63+
"metadata": {
64+
"ExecuteTime": {
65+
"end_time": "2020-04-23T18:44:33.661829Z",
66+
"start_time": "2020-04-23T18:44:33.658772Z"
67+
}
68+
},
69+
"outputs": [],
70+
"source": [
71+
"# continents with only one country\n"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": null,
77+
"metadata": {},
78+
"outputs": [],
79+
"source": [
80+
"# remove these continents"
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": [
87+
"**Create dataframe with top 3 most populated countries from each continent and store the result in dataframe with name 'world_filtered'.**\n"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {
94+
"ExecuteTime": {
95+
"end_time": "2020-04-23T18:42:59.643052Z",
96+
"start_time": "2020-04-23T18:42:59.609214Z"
97+
}
98+
},
99+
"outputs": [],
100+
"source": []
101+
},
102+
{
103+
"cell_type": "markdown",
104+
"metadata": {},
105+
"source": [
106+
"**Print the 'world_filtered' dataframe.**"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {
113+
"ExecuteTime": {
114+
"end_time": "2020-04-23T18:43:00.041229Z",
115+
"start_time": "2020-04-23T18:43:00.004937Z"
116+
}
117+
},
118+
"outputs": [],
119+
"source": []
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"metadata": {},
124+
"source": [
125+
"-----------------\n",
126+
"## Part I: Create a choropleth map of world:\n",
127+
"\n",
128+
" - First using **Geopandas**\n",
129+
" - Note: Geopandas may not work well on your computers, especially on Windows computers, it is advised to use Google Collab for this assignment. \n",
130+
" - Second using **Plotly**\n",
131+
" - Note: Plotly may not work well on Jupyter Labs, it is advised to use Jupyter Notebooks or Google Collab for the plotly portion. \n",
132+
"\n",
133+
"\n",
134+
"> #### Notes\n",
135+
"> * the colors of countries from 'world_filtered' are based on population\n",
136+
"> * other countries can stay white"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"metadata": {},
142+
"source": [
143+
"### GeoPandas"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": [
152+
"# create figure and axes\n",
153+
"\n",
154+
"\n",
155+
"\n",
156+
"# create map from world_filtered data-frame\n",
157+
"\n",
158+
"\n",
159+
"\n",
160+
"\n",
161+
"# add the rest of the countries"
162+
]
163+
},
164+
{
165+
"cell_type": "code",
166+
"execution_count": null,
167+
"metadata": {},
168+
"outputs": [],
169+
"source": []
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": null,
174+
"metadata": {},
175+
"outputs": [],
176+
"source": []
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
184+
},
185+
{
186+
"cell_type": "markdown",
187+
"metadata": {},
188+
"source": [
189+
"### Plotly"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"metadata": {},
196+
"outputs": [],
197+
"source": []
198+
},
199+
{
200+
"cell_type": "code",
201+
"execution_count": null,
202+
"metadata": {},
203+
"outputs": [],
204+
"source": []
205+
},
206+
{
207+
"cell_type": "code",
208+
"execution_count": null,
209+
"metadata": {},
210+
"outputs": [],
211+
"source": []
212+
},
213+
{
214+
"cell_type": "markdown",
215+
"metadata": {},
216+
"source": [
217+
"-----------\n",
218+
"## Part II: More Geopandas\n",
219+
"\n",
220+
"In Geopandas:\n",
221+
"\n",
222+
"* add New York, Berlin, Paris, Toronto, Calgary, Tokyo to the map you have created before\n",
223+
" * to get geometry of these cities use the function, **gpd.tools.geocode**(['New York', 'Berlin', 'Paris','Toronto', 'Calgary', 'Tokyo'])\n",
224+
" * if you do not have the geopy library instaled, install it with the following command **in the jupyter notebook cell** `!pip install geopy` "
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": null,
230+
"metadata": {
231+
"ExecuteTime": {
232+
"end_time": "2020-04-23T18:44:34.757007Z",
233+
"start_time": "2020-04-23T18:44:34.752365Z"
234+
}
235+
},
236+
"outputs": [],
237+
"source": [
238+
"# get geometry\n",
239+
"\n",
240+
"\n",
241+
"# create figure and axes\n",
242+
"\n",
243+
"\n",
244+
"\n",
245+
"\n",
246+
"# create map from world_filtered data-frame\n",
247+
"\n",
248+
"\n",
249+
"\n",
250+
"\n",
251+
"# add the rest of the countries\n",
252+
"\n",
253+
"\n",
254+
"\n",
255+
"# add cities\n"
256+
]
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": null,
261+
"metadata": {},
262+
"outputs": [],
263+
"source": []
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": null,
268+
"metadata": {},
269+
"outputs": [],
270+
"source": []
271+
},
272+
{
273+
"cell_type": "code",
274+
"execution_count": null,
275+
"metadata": {},
276+
"outputs": [],
277+
"source": []
278+
}
279+
],
280+
"metadata": {
281+
"kernelspec": {
282+
"display_name": "Python 3",
283+
"language": "python",
284+
"name": "python3"
285+
},
286+
"language_info": {
287+
"codemirror_mode": {
288+
"name": "ipython",
289+
"version": 3
290+
},
291+
"file_extension": ".py",
292+
"mimetype": "text/x-python",
293+
"name": "python",
294+
"nbconvert_exporter": "python",
295+
"pygments_lexer": "ipython3",
296+
"version": "3.7.9"
297+
},
298+
"toc": {
299+
"base_numbering": 1,
300+
"nav_menu": {},
301+
"number_sections": true,
302+
"sideBar": true,
303+
"skip_h1_title": false,
304+
"title_cell": "Table of Contents",
305+
"title_sidebar": "Contents",
306+
"toc_cell": false,
307+
"toc_position": {},
308+
"toc_section_display": true,
309+
"toc_window_display": false
310+
},
311+
"varInspector": {
312+
"cols": {
313+
"lenName": 16,
314+
"lenType": 16,
315+
"lenVar": 40
316+
},
317+
"kernels_config": {
318+
"python": {
319+
"delete_cmd_postfix": "",
320+
"delete_cmd_prefix": "del ",
321+
"library": "var_list.py",
322+
"varRefreshCmd": "print(var_dic_list())"
323+
},
324+
"r": {
325+
"delete_cmd_postfix": ") ",
326+
"delete_cmd_prefix": "rm(",
327+
"library": "var_list.r",
328+
"varRefreshCmd": "cat(var_dic_list()) "
329+
}
330+
},
331+
"types_to_exclude": [
332+
"module",
333+
"function",
334+
"builtin_function_or_method",
335+
"instance",
336+
"_Feature"
337+
],
338+
"window_display": false
339+
}
340+
},
341+
"nbformat": 4,
342+
"nbformat_minor": 4
343+
}

0 commit comments

Comments
 (0)