From 35a9fa8682a7cdfa86df56e5d8f408bd642cf2d2 Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Mon, 26 Aug 2019 17:17:31 -0400 Subject: [PATCH 1/3] reorder cells --- README.md | 2 +- index.ipynb | 450 +--------------------------------------------------- 2 files changed, 2 insertions(+), 450 deletions(-) diff --git a/README.md b/README.md index 4285332623c..084330bcf79 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### Introduction -Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. +Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. ### Working with lists and maps diff --git a/index.ipynb b/index.ipynb index d36bbeafb3a..45a6a95596f 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1,449 +1 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "# Lists and Maps Lab" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Introduction" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Working with lists and maps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> Press shift + enter on this cell and all following code cells." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Assign the variable `palermo` to the first element of the `neighborhoods` list." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "palermo = None" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now assign the variable `la_boca` to the last element of our list." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "la_boca = None" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "coordinates = [-34.6037, -58.3816]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ba_latitude = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ba_longitude = None" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now let's see if we can display this as a map." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!pip install folium" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "import folium\n", - "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", - "buenos_map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All of that from a couple of lines of code. Let's understand it:\n", - "\n", - "```python\n", - "import folium\n", - "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", - "buenos_map\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos`. Since `buenos_map` is the last line of a cell, the map is displayed." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", - "buenos_marker.add_to(buenos_map)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's see our updated map! We see our map by referencing our `buenos_map` variable." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "buenos_map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Great! Note that both the map object and the map marker are just stored as variables." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "buenos_marker" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "And just like any other piece of\n", - "data in Python, we can place this marker in a list, and then retrieve it from the list." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "buenos_markers = [buenos_marker]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "buenos_markers[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", - "marker_one = folium.Marker([-34.5711, -58.4233])\n", - "marker_two = folium.Marker([-34.5895, -58.3974])\n", - "marker_three = folium.Marker([-34.6212, -58.3731])\n", - "marker_four = folium.Marker([-34.6177, -58.3621])\n", - "marker_five = folium.Marker([-34.603722, -58.381592])\n", - "marker_six = folium.Marker([-34.6345, -58.3631])\n", - "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Assign `la_boca_marker` equal to the last marker." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "la_boca_marker = None" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import folium\n", - "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", - "la_boca_marker.add_to(buenos_map)\n", - "buenos_map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "neighborhood_markers.pop()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(len(neighborhood_markers)) # 5\n", - "print(neighborhood_markers[-1] == marker_five) # True" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "recoleta_marker = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "recoleta_marker.add_to(buenos_map)\n", - "buenos_map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for marker in neighborhood_markers:\n", - " marker.add_to(buenos_map)\n", - "buenos_map" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "But that's a lesson for another day." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Summary" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists and Maps Lab"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Working with lists and maps"]}, {"cell_type": "markdown", "metadata": {}, "source": ["As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Press shift + enter on this cell and all following code cells."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign the variable `palermo` to the first element of the `neighborhoods` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["palermo = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign the variable `la_boca` to the last element of our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["coordinates = [-34.6037, -58.3816]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_latitude = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_longitude = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now let's see if we can display this as a map."]}, {"cell_type": "markdown", "metadata": {}, "source": ["First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install folium"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["All of that from a couple of lines of code. Let's understand it:\n", "\n", "```python\n", "import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map\n", "```"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos`. Since `buenos_map` is the last line of a cell, the map is displayed."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", "buenos_marker.add_to(buenos_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's see our updated map! We see our map by referencing our `buenos_map` variable."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Great! Note that both the map object and the map marker are just stored as variables."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_marker"]}, {"cell_type": "markdown", "metadata": {}, "source": ["And just like any other piece of\n", "data in Python, we can place this marker in a list, and then retrieve it from the list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers = [buenos_marker]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers[0]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", "marker_one = folium.Marker([-34.5711, -58.4233])\n", "marker_two = folium.Marker([-34.5895, -58.3974])\n", "marker_three = folium.Marker([-34.6212, -58.3731])\n", "marker_four = folium.Marker([-34.6177, -58.3621])\n", "marker_five = folium.Marker([-34.603722, -58.381592])\n", "marker_six = folium.Marker([-34.6345, -58.3631])\n", "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign `la_boca_marker` equal to the last marker."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca_marker = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", "la_boca_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhood_markers.pop()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["print(len(neighborhood_markers)) # 5\n", "print(neighborhood_markers[-1] == marker_five) # True"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["for marker in neighborhood_markers:\n", " marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["But that's a lesson for another day."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file From 57c16c278fa71a3dc70bc707592c726ac06c3a70 Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Fri, 30 Aug 2019 17:24:42 -0400 Subject: [PATCH 2/3] fix typo --- README.md | 2 +- index.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 084330bcf79..9ad1c64c133 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ buenos_map = folium.Map([ba_latitude, ba_longitude]) buenos_map ``` -> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos`. Since `buenos_map` is the last line of a cell, the map is displayed. +> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos_map`. Since `buenos_map` is the last line of a cell, the map is displayed. Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates. diff --git a/index.ipynb b/index.ipynb index 45a6a95596f..37f3705fecc 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists and Maps Lab"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Working with lists and maps"]}, {"cell_type": "markdown", "metadata": {}, "source": ["As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Press shift + enter on this cell and all following code cells."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign the variable `palermo` to the first element of the `neighborhoods` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["palermo = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign the variable `la_boca` to the last element of our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["coordinates = [-34.6037, -58.3816]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_latitude = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_longitude = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now let's see if we can display this as a map."]}, {"cell_type": "markdown", "metadata": {}, "source": ["First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install folium"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["All of that from a couple of lines of code. Let's understand it:\n", "\n", "```python\n", "import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map\n", "```"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos`. Since `buenos_map` is the last line of a cell, the map is displayed."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", "buenos_marker.add_to(buenos_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's see our updated map! We see our map by referencing our `buenos_map` variable."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Great! Note that both the map object and the map marker are just stored as variables."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_marker"]}, {"cell_type": "markdown", "metadata": {}, "source": ["And just like any other piece of\n", "data in Python, we can place this marker in a list, and then retrieve it from the list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers = [buenos_marker]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers[0]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", "marker_one = folium.Marker([-34.5711, -58.4233])\n", "marker_two = folium.Marker([-34.5895, -58.3974])\n", "marker_three = folium.Marker([-34.6212, -58.3731])\n", "marker_four = folium.Marker([-34.6177, -58.3621])\n", "marker_five = folium.Marker([-34.603722, -58.381592])\n", "marker_six = folium.Marker([-34.6345, -58.3631])\n", "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign `la_boca_marker` equal to the last marker."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca_marker = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", "la_boca_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhood_markers.pop()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["print(len(neighborhood_markers)) # 5\n", "print(neighborhood_markers[-1] == marker_five) # True"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["for marker in neighborhood_markers:\n", " marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["But that's a lesson for another day."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists and Maps Lab"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Working with lists and maps"]}, {"cell_type": "markdown", "metadata": {}, "source": ["As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Press shift + enter on this cell and all following code cells."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign the variable `palermo` to the first element of the `neighborhoods` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["palermo = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign the variable `la_boca` to the last element of our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["coordinates = [-34.6037, -58.3816]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_latitude = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_longitude = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now let's see if we can display this as a map."]}, {"cell_type": "markdown", "metadata": {}, "source": ["First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install folium"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["All of that from a couple of lines of code. Let's understand it:\n", "\n", "```python\n", "import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map\n", "```"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos_map`. Since `buenos_map` is the last line of a cell, the map is displayed."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", "buenos_marker.add_to(buenos_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's see our updated map! We see our map by referencing our `buenos_map` variable."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Great! Note that both the map object and the map marker are just stored as variables."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_marker"]}, {"cell_type": "markdown", "metadata": {}, "source": ["And just like any other piece of\n", "data in Python, we can place this marker in a list, and then retrieve it from the list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers = [buenos_marker]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers[0]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", "marker_one = folium.Marker([-34.5711, -58.4233])\n", "marker_two = folium.Marker([-34.5895, -58.3974])\n", "marker_three = folium.Marker([-34.6212, -58.3731])\n", "marker_four = folium.Marker([-34.6177, -58.3621])\n", "marker_five = folium.Marker([-34.603722, -58.381592])\n", "marker_six = folium.Marker([-34.6345, -58.3631])\n", "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign `la_boca_marker` equal to the last marker."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca_marker = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", "la_boca_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhood_markers.pop()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["print(len(neighborhood_markers)) # 5\n", "print(neighborhood_markers[-1] == marker_five) # True"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["for marker in neighborhood_markers:\n", " marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["But that's a lesson for another day."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file From 0124714681f9e22db2098c4418af66a131a472ff Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Mon, 16 Sep 2019 15:17:09 -0400 Subject: [PATCH 3/3] wording --- README.md | 2 +- index.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ad1c64c133..bee878331f8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### Introduction -Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. +Ok, so now that we have a sense of how to read from and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. ### Working with lists and maps diff --git a/index.ipynb b/index.ipynb index 37f3705fecc..a6516ccf165 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists and Maps Lab"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Working with lists and maps"]}, {"cell_type": "markdown", "metadata": {}, "source": ["As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Press shift + enter on this cell and all following code cells."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign the variable `palermo` to the first element of the `neighborhoods` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["palermo = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign the variable `la_boca` to the last element of our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["coordinates = [-34.6037, -58.3816]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_latitude = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_longitude = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now let's see if we can display this as a map."]}, {"cell_type": "markdown", "metadata": {}, "source": ["First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install folium"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["All of that from a couple of lines of code. Let's understand it:\n", "\n", "```python\n", "import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map\n", "```"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos_map`. Since `buenos_map` is the last line of a cell, the map is displayed."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", "buenos_marker.add_to(buenos_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's see our updated map! We see our map by referencing our `buenos_map` variable."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Great! Note that both the map object and the map marker are just stored as variables."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_marker"]}, {"cell_type": "markdown", "metadata": {}, "source": ["And just like any other piece of\n", "data in Python, we can place this marker in a list, and then retrieve it from the list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers = [buenos_marker]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers[0]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", "marker_one = folium.Marker([-34.5711, -58.4233])\n", "marker_two = folium.Marker([-34.5895, -58.3974])\n", "marker_three = folium.Marker([-34.6212, -58.3731])\n", "marker_four = folium.Marker([-34.6177, -58.3621])\n", "marker_five = folium.Marker([-34.603722, -58.381592])\n", "marker_six = folium.Marker([-34.6345, -58.3631])\n", "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign `la_boca_marker` equal to the last marker."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca_marker = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", "la_boca_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhood_markers.pop()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["print(len(neighborhood_markers)) # 5\n", "print(neighborhood_markers[-1] == marker_five) # True"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["for marker in neighborhood_markers:\n", " marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["But that's a lesson for another day."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists and Maps Lab"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from and alter a list in Python, let's see how our knowledge of lists can help us in creating data visualizations by plotting maps. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Working with lists and maps"]}, {"cell_type": "markdown", "metadata": {}, "source": ["As we know, lists are used to store a collection of data. In describing a city, we can use lists to organize our data in all sorts of ways. For example, here is a list of neighborhoods in the city of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Press shift + enter on this cell and all following code cells."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign the variable `palermo` to the first element of the `neighborhoods` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["palermo = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign the variable `la_boca` to the last element of our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Beyond the neighborhoods, another thing that we can think of representing as a collection are the coordinates of a city, latitude and longitude. Below, our `coordinates` list contains the coordinates for Buenos Aires. The first element is latitude and the second is longitude."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["coordinates = [-34.6037, -58.3816]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Set `ba_latitude` to equal the latitude of Buenos Aires and set `ba_longitude` to the longitude of Buenos Aires."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_latitude = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["ba_longitude = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now let's see if we can display this as a map."]}, {"cell_type": "markdown", "metadata": {}, "source": ["First we download a mapping library with `pip`. Remember a library is simply a tool comprised of code hosted somewhere else on the internet and which we download to use in our current project. Pip is another tool that allows us to easily download various Python libraries from the Internet. "]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install folium"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Press shift + enter on the above code, and our `folium` library is available to us. Now we just tell Python that we will be using `folium` in our codebase by writing `import folium` in the next cell. Once the import is complete we will be able to display some maps with the help of `folium`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["All of that from a couple of lines of code. Let's understand it:\n", "\n", "```python\n", "import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude])\n", "buenos_map\n", "```"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> [Folium](https://github.com/python-visualization/folium) is a mapping library built on Python. We created a representation of a map, by referencing the `folium.Map` function and passing through a list. That list represents the latitude and longitude, just like we saw previously. The map object is stored as the variable `buenos_map`. Since `buenos_map` is the last line of a cell, the map is displayed."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now we can also add a marker to this map. For now, let's start by adding a marker for our Buenos Aires coordinates."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["buenos_marker = folium.Marker([ba_latitude, ba_longitude])\n", "buenos_marker.add_to(buenos_map)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["So we used the `folium` library to create a marker. We specified the coordinates of the marker as a list. Finally, we added the marker to our map with the `add_to` function."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let's see our updated map! We see our map by referencing our `buenos_map` variable."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Great! Note that both the map object and the map marker are just stored as variables."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_marker"]}, {"cell_type": "markdown", "metadata": {}, "source": ["And just like any other piece of\n", "data in Python, we can place this marker in a list, and then retrieve it from the list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers = [buenos_marker]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["buenos_markers[0]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Recall our `neighborhoods` list from above. The coordinates in the markers below match the neighborhoods in our `neighborhoods` list, respectively."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhoods = ['Palermo', 'Ricoleta', 'Santelmo', 'Puerto Madero', 'Belgrano', 'La Boca']\n", "marker_one = folium.Marker([-34.5711, -58.4233])\n", "marker_two = folium.Marker([-34.5895, -58.3974])\n", "marker_three = folium.Marker([-34.6212, -58.3731])\n", "marker_four = folium.Marker([-34.6177, -58.3621])\n", "marker_five = folium.Marker([-34.603722, -58.381592])\n", "marker_six = folium.Marker([-34.6345, -58.3631])\n", "neighborhood_markers = [marker_one, marker_two, marker_three, marker_four, marker_five, marker_six]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Assign `la_boca_marker` equal to the last marker."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["la_boca_marker = None"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Below, we will rewrite `buenos_map` variable to create a new map of Buenos Aires, but this time we will add `la_boca_marker` to the map and zoom in a bit using the `zoom_start` attribute."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import folium\n", "buenos_map = folium.Map([ba_latitude, ba_longitude], zoom_start = 12)\n", "la_boca_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now that we plotted `la_boca_marker` we don't need the marker anymore. So, let's remove this last element from our `neighborhood_markers` list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["neighborhood_markers.pop()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["print(len(neighborhood_markers)) # 5\n", "print(neighborhood_markers[-1] == marker_five) # True"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now assign `recoleta_marker` to the second marker in the `neighborhood_markers` list. This time, we won't reassign our `buenos_map` so we should expect both `la_boca_marker` and `recoleta_marker` to appear!"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["recoleta_marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Don't worry if this feels tedious and manual. When we get up to loops in Python, we will see how to easily plot all of the markers in our list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["for marker in neighborhood_markers:\n", " marker.add_to(buenos_map)\n", "buenos_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["But that's a lesson for another day."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson we saw how to select information from a list and then plot that information with maps. We saw that lists can make good arguments to methods, as they represent an ordered collection of information, like latitude followed by longitude. In just a few lessons we saw how to use Python to make visualizations with our data going forward."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file