From 50efb497a3cbc0a210cf612931f5383af018ba78 Mon Sep 17 00:00:00 2001 From: Vincent Rufa Date: Sat, 1 Dec 2018 02:12:25 +0000 Subject: [PATCH] Automatically backed up by Learn --- .~index.ipynb | 449 ++++++++++++++++++++++++++++++++++++++++++++ index.ipynb | 449 -------------------------------------------- index.ipynb.invalid | 0 3 files changed, 449 insertions(+), 449 deletions(-) create mode 100644 .~index.ipynb create mode 100644 index.ipynb.invalid diff --git a/.~index.ipynb b/.~index.ipynb new file mode 100644 index 00000000000..d36bbeafb3a --- /dev/null +++ b/.~index.ipynb @@ -0,0 +1,449 @@ +{ + "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 +} diff --git a/index.ipynb b/index.ipynb index d36bbeafb3a..e69de29bb2d 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1,449 +0,0 @@ -{ - "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 -} diff --git a/index.ipynb.invalid b/index.ipynb.invalid new file mode 100644 index 00000000000..e69de29bb2d