diff --git a/.DS_Store b/.DS_Store index eeb51de..4985879 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/module-1/.DS_Store b/module-1/.DS_Store index dc90db0..9f229fb 100644 Binary files a/module-1/.DS_Store and b/module-1/.DS_Store differ diff --git a/module-1/lab-numpy/.DS_Store b/module-1/lab-numpy/.DS_Store index dc0ae86..24d19f1 100644 Binary files a/module-1/lab-numpy/.DS_Store and b/module-1/lab-numpy/.DS_Store differ diff --git a/module-1/lab-resolving-git-conflicts/.DS_Store b/module-1/lab-resolving-git-conflicts/.DS_Store index 045803a..56adc1d 100644 Binary files a/module-1/lab-resolving-git-conflicts/.DS_Store and b/module-1/lab-resolving-git-conflicts/.DS_Store differ diff --git a/module-1/lab-resolving-git-conflicts/your-code/about-me.md b/module-1/lab-resolving-git-conflicts/your-code/about-me.md index 30a999d..14a2186 100755 --- a/module-1/lab-resolving-git-conflicts/your-code/about-me.md +++ b/module-1/lab-resolving-git-conflicts/your-code/about-me.md @@ -1,3 +1,4 @@ +QUE VIVA EL CONFLICTO! mentira, no queremos que viva. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra laoreet lorem et dapibus. Integer auctor dignissim egestas. Ut id purus neque. Pellentesque imperdiet lacus in libero laoreet, at tempus felis tristique. Cras fermentum erat a dui vulputate gravida. Nulla aliquet nisi interdum nulla pretium, ac vestibulum diam congue. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus lacus risus, sodales vitae viverra quis, maximus ac ipsum. Sed consequat viverra mattis. Curabitur iaculis varius mollis. Ut porttitor iaculis tellus bibendum euismod. Morbi porta, ante nec tempus porta, felis mi faucibus lacus, sed tristique purus nunc sed est. Aenean pulvinar urna ut lacus interdum aliquam. Pellentesque sit amet magna accumsan, sagittis metus a, volutpat velit. Mauris vitae ex vehicula, posuere nisi sed, sagittis nunc. Ut scelerisque, mi non tristique tristique, mi enim luctus nunc, eu mattis sem quam auctor nunc. Donec lobortis tellus eget blandit ultricies. Vivamus euismod metus eget leo blandit, at malesuada magna efficitur. Praesent sodales faucibus mi, ullamcorper ultrices orci. Vivamus maximus malesuada massa, nec placerat leo feugiat vel. Nam vitae eleifend enim. Nullam interdum ipsum velit, vitae faucibus lectus blandit euismod. diff --git a/module-2/.DS_Store b/module-2/.DS_Store index b08810b..de4d598 100644 Binary files a/module-2/.DS_Store and b/module-2/.DS_Store differ diff --git a/module-2/python-bi-project/.DS_Store b/module-2/python-bi-project/.DS_Store new file mode 100644 index 0000000..c893ab4 Binary files /dev/null and b/module-2/python-bi-project/.DS_Store differ diff --git a/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/Project - Final-checkpoint.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/Project - Final-checkpoint.ipynb new file mode 100644 index 0000000..adca703 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/Project - Final-checkpoint.ipynb @@ -0,0 +1,2923 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Exploring data" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import pymongo\n", + "from pymongo import MongoClient\n", + "from tqdm import tqdm\n", + "from tqdm import trange\n", + "import folium\n", + "from folium import plugins\n", + "import numpy as np\n", + "import warnings\n", + "warnings.simplefilter('ignore')\n", + "import re\n", + "import pickle\n", + "from opencage.geocoder import OpenCageGeocode" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#creating the Mongo conection\n", + "cliente=MongoClient('mongodb://localhost:27017')\n", + "db = cliente.companies\n", + "col = db.companies" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
5 rows × 42 columns
26428 rows × 6 columns
1 rows × 42 columns
Google provides search and advertising serv...\n", + "image {'available_sizes': [[[150, 51], 'assets/image...\n", + "products [{'name': 'Gmail', 'permalink': 'gmail'}, {'na...\n", + "relationships [{'is_past': False, 'title': 'CEO of Google Co...\n", + "competitions [{'competitor': {'name': 'Technorati', 'permal...\n", + "providerships [{'title': 'Public Relations (APAC)', 'is_past...\n", + "total_money_raised $555M\n", + "funding_rounds [{'id': 380, 'round_code': 'angel', 'source_ur...\n", + "investments [{'funding_round': {'round_code': 'a', 'source...\n", + "acquisition None\n", + "acquisitions [{'price_amount': 60000000, 'price_currency_co...\n", + "offices [{'description': 'Google Headquarters', 'addre...\n", + "milestones [{'id': 3, 'description': 'More than 4 Billion...\n", + "video_embeds [{'embed_code': '\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " description\n", + " address1\n", + " address2\n", + " zip_code\n", + " city\n", + " state_code\n", + " country_code\n", + " latitude\n", + " longitude\n", + " name\n", + " total_number_of_employees\n", + " category\n", + " principal\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " Google Headquarters\n", + " 1600 Amphitheatre Parkway\n", + " \n", + " \n", + " Mountain View\n", + " CA\n", + " USA\n", + " 37.421972\n", + " -122.084143\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-122.084143,...\n", + " \n", + " \n", + " 1\n", + " Google Ann Arbor\n", + " 112 S. Main St.\n", + " 2nd Floor\n", + " 48104\n", + " Ann Arbor\n", + " MI\n", + " USA\n", + " 42.280988\n", + " -83.748882\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-83.748882, ...\n", + " \n", + " \n", + " 2\n", + " Google Atlanta\n", + " 10 10th Street NE\n", + " Suite 600\n", + " 30309\n", + " Atlanta\n", + " GA\n", + " USA\n", + " 33.781466\n", + " -84.387519\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-84.387519, ...\n", + " \n", + " \n", + " 3\n", + " Google Austin\n", + " Plaza 7000\n", + " 7000 North MoPac Expressway, 2nd Floor\n", + " 78731\n", + " Austin\n", + " TX\n", + " USA\n", + " 30.351416\n", + " -97.751382\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-97.751382, ...\n", + " \n", + " \n", + " 4\n", + " Google Boulder\n", + " 2590 Pearl Street\n", + " Suite 100\n", + " 80302\n", + " Boulder\n", + " CO\n", + " USA\n", + " 40.021416\n", + " -105.260931\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-105.260931,...\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " description address1 \\\n", + "0 Google Headquarters 1600 Amphitheatre Parkway \n", + "1 Google Ann Arbor 112 S. Main St. \n", + "2 Google Atlanta 10 10th Street NE \n", + "3 Google Austin Plaza 7000 \n", + "4 Google Boulder 2590 Pearl Street \n", + "\n", + " address2 zip_code city state_code \\\n", + "0 Mountain View CA \n", + "1 2nd Floor 48104 Ann Arbor MI \n", + "2 Suite 600 30309 Atlanta GA \n", + "3 7000 North MoPac Expressway, 2nd Floor 78731 Austin TX \n", + "4 Suite 100 80302 Boulder CO \n", + "\n", + " country_code latitude longitude name total_number_of_employees \\\n", + "0 USA 37.421972 -122.084143 Google 28000.0 \n", + "1 USA 42.280988 -83.748882 Google 28000.0 \n", + "2 USA 33.781466 -84.387519 Google 28000.0 \n", + "3 USA 30.351416 -97.751382 Google 28000.0 \n", + "4 USA 40.021416 -105.260931 Google 28000.0 \n", + "\n", + " category principal \n", + "0 search {'type': 'Point', 'coordinates': [-122.084143,... \n", + "1 search {'type': 'Point', 'coordinates': [-83.748882, ... \n", + "2 search {'type': 'Point', 'coordinates': [-84.387519, ... \n", + "3 search {'type': 'Point', 'coordinates': [-97.751382, ... \n", + "4 search {'type': 'Point', 'coordinates': [-105.260931,... " + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test1 = pd.DataFrame(data.iloc[48].offices)\n", + "test1['name'] = str(data.loc[48,['name'][0]])\n", + "test1['total_number_of_employees'] = data.iloc[48].number_of_employees\n", + "test1['category'] = str(data.loc[48,['category_code'][0]])\n", + "test1['principal'] = pd.Series(lista_x)\n", + "test1.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[\"{'type': 'Point', 'coordinates': [-122.084143, 37.421972]}\",\n", + " \"{'type': 'Point', 'coordinates': [-83.748882, 42.280988]}\",\n", + " \"{'type': 'Point', 'coordinates': [-84.387519, 33.781466]}\",\n", + " \"{'type': 'Point', 'coordinates': [-97.751382, 30.351416]}\",\n", + " \"{'type': 'Point', 'coordinates': [-105.260931, 40.021416]}\",\n", + " \"{'type': 'Point', 'coordinates': [-71.087478, 42.36305]}\",\n", + " \"{'type': 'Point', 'coordinates': [-87.628912, 41.889474]}\",\n", + " \"{'type': 'Point', 'coordinates': [-97.018196, 32.981465]}\",\n", + " \"{'type': 'Point', 'coordinates': [-96.807693, 32.809161]}\",\n", + " \"{'type': 'Point', 'coordinates': [-104.898419, 39.62919]}\",\n", + " \"{'type': 'Point', 'coordinates': [-83.215498, 42.547807]}\",\n", + " \"{'type': 'Point', 'coordinates': [-117.861817, 33.658331]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [-74.004489, 40.74222]}\",\n", + " \"{'type': 'Point', 'coordinates': [-111.926263, 33.411898]}\",\n", + " \"{'type': 'Point', 'coordinates': [-79.946269, 40.444528]}\",\n", + " \"{'type': 'Point', 'coordinates': [-122.389757, 37.789803]}\",\n", + " \"{'type': 'Point', 'coordinates': [-118.494288, 34.019282]}\",\n", + " \"{'type': 'Point', 'coordinates': [-122.351397, 47.675326]}\",\n", + " \"{'type': 'Point', 'coordinates': [-122.350592, 47.649701]}\",\n", + " \"{'type': 'Point', 'coordinates': [-77.027101, 38.901113]}\",\n", + " \"{'type': 'Point', 'coordinates': [145.073608, -37.879234]}\",\n", + " \"{'type': 'Point', 'coordinates': [138.612396, -34.822723]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [77.122261, 28.86999]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [10.187799, 56.171882]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [2.332749, 48.869606]}\",\n", + " \"{'type': 'Point', 'coordinates': [9.985266, 53.554052]}\",\n", + " \"{'type': 'Point', 'coordinates': [-6.234424, 53.339914]}\",\n", + " \"{'type': 'Point', 'coordinates': [9.195978, 45.46381]}\",\n", + " \"{'type': 'Point', 'coordinates': [4.871464, 52.337495]}\",\n", + " \"{'type': 'Point', 'coordinates': [10.741047, 59.915848]}\",\n", + " \"{'type': 'Point', 'coordinates': [10.412428, 63.435324]}\",\n", + " \"{'type': 'Point', 'coordinates': [19.929806, 50.063281]}\",\n", + " \"{'type': 'Point', 'coordinates': [17.041942, 51.116574]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [22.126255, 65.617491]}\",\n", + " \"{'type': 'Point', 'coordinates': [18.060162, 59.332344]}\",\n", + " \"{'type': 'Point', 'coordinates': [8.524864, 47.36554]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [-2.250166, 53.473606]}\",\n", + " \"{'type': 'Point', 'coordinates': [-73.567044, 45.498588]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [-80.546381, 43.474704]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [-46.681494, -23.590463]}\",\n", + " \"{'type': 'Point', 'coordinates': [-99.030156, 19.507519]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\",\n", + " \"{'type': 'Point', 'coordinates': [nan, nan]}\"]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lista_x" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 -122.084143\n", + "1 -83.748882\n", + "2 -84.387519\n", + "3 -97.751382\n", + "4 -105.260931\n", + " ... \n", + "62 -99.030156\n", + "63 NaN\n", + "64 NaN\n", + "65 NaN\n", + "66 NaN\n", + "Name: longitude, Length: 67, dtype: float64" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test1.longitude" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "principal = {'type':'Point',\n", + " 'coordinates': [test1.longitude[0],\n", + " test1.latitude[0]]}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'type': 'Point', 'coordinates': [-122.084143, 37.421972]}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "principal" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "def principal(x):\n", + " principal = {'type':'Point',\n", + " 'coordinates': [x.longitude,\n", + " x.latitude]}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'search'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(data.loc[48,['category_code'][0]])\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "al_menos_1_ofi=db.companies.find({'offices': {'$not': {'$size':0}}},\n", + " {'name':1, '_id':0, 'offices':1})" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['_id', 'name', 'permalink', 'crunchbase_url', 'homepage_url',\n", + " 'blog_url', 'blog_feed_url', 'twitter_username', 'category_code',\n", + " 'number_of_employees', 'founded_year', 'founded_month', 'founded_day',\n", + " 'deadpooled_year', 'tag_list', 'alias_list', 'email_address',\n", + " 'phone_number', 'description', 'created_at', 'updated_at', 'overview',\n", + " 'image', 'products', 'relationships', 'competitions', 'providerships',\n", + " 'total_money_raised', 'funding_rounds', 'investments', 'acquisition',\n", + " 'acquisitions', 'offices', 'milestones', 'video_embeds', 'screenshots',\n", + " 'external_links', 'partners', 'deadpooled_month', 'deadpooled_day',\n", + " 'deadpooled_url', 'ipo'],\n", + " dtype='object')" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 224, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 13744 entries, 0 to 13743\n", + "Data columns (total 4 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 name 13744 non-null object \n", + " 1 category_code 13092 non-null object \n", + " 2 number_of_employees 7467 non-null float64\n", + " 3 offices 13744 non-null object \n", + "dtypes: float64(1), object(3)\n", + "memory usage: 429.6+ KB\n" + ] + }, + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'head'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'head'" + ] + } + ], + "source": [ + "data.info().head()" + ] + }, + { + "cell_type": "code", + "execution_count": 223, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "web 2812\n", + "software 2387\n", + "games_video 839\n", + "mobile 821\n", + "advertising 794\n", + "Name: category_code, dtype: int64" + ] + }, + "execution_count": 223, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.category_code.value_counts().head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " description\n", + " address1\n", + " address2\n", + " zip_code\n", + " city\n", + " state_code\n", + " country_code\n", + " latitude\n", + " longitude\n", + " name\n", + " total_number_of_employees\n", + " category\n", + " principal\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " Google Headquarters\n", + " 1600 Amphitheatre Parkway\n", + " \n", + " \n", + " Mountain View\n", + " CA\n", + " USA\n", + " 37.421972\n", + " -122.084143\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-122.084143,...\n", + " \n", + " \n", + " 1\n", + " Google Ann Arbor\n", + " 112 S. Main St.\n", + " 2nd Floor\n", + " 48104\n", + " Ann Arbor\n", + " MI\n", + " USA\n", + " 42.280988\n", + " -83.748882\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-83.748882, ...\n", + " \n", + " \n", + " 2\n", + " Google Atlanta\n", + " 10 10th Street NE\n", + " Suite 600\n", + " 30309\n", + " Atlanta\n", + " GA\n", + " USA\n", + " 33.781466\n", + " -84.387519\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-84.387519, ...\n", + " \n", + " \n", + " 3\n", + " Google Austin\n", + " Plaza 7000\n", + " 7000 North MoPac Expressway, 2nd Floor\n", + " 78731\n", + " Austin\n", + " TX\n", + " USA\n", + " 30.351416\n", + " -97.751382\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-97.751382, ...\n", + " \n", + " \n", + " 4\n", + " Google Boulder\n", + " 2590 Pearl Street\n", + " Suite 100\n", + " 80302\n", + " Boulder\n", + " CO\n", + " USA\n", + " 40.021416\n", + " -105.260931\n", + " Google\n", + " 28000.0\n", + " search\n", + " {'type': 'Point', 'coordinates': [-105.260931,...\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " description address1 \\\n", + "0 Google Headquarters 1600 Amphitheatre Parkway \n", + "1 Google Ann Arbor 112 S. Main St. \n", + "2 Google Atlanta 10 10th Street NE \n", + "3 Google Austin Plaza 7000 \n", + "4 Google Boulder 2590 Pearl Street \n", + "\n", + " address2 zip_code city state_code \\\n", + "0 Mountain View CA \n", + "1 2nd Floor 48104 Ann Arbor MI \n", + "2 Suite 600 30309 Atlanta GA \n", + "3 7000 North MoPac Expressway, 2nd Floor 78731 Austin TX \n", + "4 Suite 100 80302 Boulder CO \n", + "\n", + " country_code latitude longitude name total_number_of_employees \\\n", + "0 USA 37.421972 -122.084143 Google 28000.0 \n", + "1 USA 42.280988 -83.748882 Google 28000.0 \n", + "2 USA 33.781466 -84.387519 Google 28000.0 \n", + "3 USA 30.351416 -97.751382 Google 28000.0 \n", + "4 USA 40.021416 -105.260931 Google 28000.0 \n", + "\n", + " category principal \n", + "0 search {'type': 'Point', 'coordinates': [-122.084143,... \n", + "1 search {'type': 'Point', 'coordinates': [-83.748882, ... \n", + "2 search {'type': 'Point', 'coordinates': [-84.387519, ... \n", + "3 search {'type': 'Point', 'coordinates': [-97.751382, ... \n", + "4 search {'type': 'Point', 'coordinates': [-105.260931,... " + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test1 = pd.DataFrame(data.iloc[48].offices)\n", + "test1['name'] = str(data.loc[48,['name'][0]])\n", + "test1['total_number_of_employees'] = data.iloc[48].number_of_employees\n", + "test1['category'] = str(data.loc[48,['category_code'][0]])\n", + "test1['principal'] = pd.Series(lista_x)\n", + "test1.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "al_menos_1_ofi=db.companies.find({'offices': {'$not': {'$size':0}}},\n", + " {'name':1,'number_of_employees':1, '_id':0, 'offices':1,'category_code':1\n", + " })" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " name\n", + " category_code\n", + " number_of_employees\n", + " offices\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " Wetpaint\n", + " web\n", + " 47.0\n", + " [{'description': '', 'address1': '710 - 2nd Av...\n", + " \n", + " \n", + " 1\n", + " AdventNet\n", + " enterprise\n", + " 600.0\n", + " [{'description': 'Headquarters', 'address1': '...\n", + " \n", + " \n", + " 2\n", + " Zoho\n", + " software\n", + " 1600.0\n", + " [{'description': 'Headquarters', 'address1': '...\n", + " \n", + " \n", + " 3\n", + " Digg\n", + " news\n", + " 60.0\n", + " [{'description': None, 'address1': '135 Missis...\n", + " \n", + " \n", + " 4\n", + " Facebook\n", + " social\n", + " 5299.0\n", + " [{'description': 'Headquarters', 'address1': '...\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " name category_code number_of_employees \\\n", + "0 Wetpaint web 47.0 \n", + "1 AdventNet enterprise 600.0 \n", + "2 Zoho software 1600.0 \n", + "3 Digg news 60.0 \n", + "4 Facebook social 5299.0 \n", + "\n", + " offices \n", + "0 [{'description': '', 'address1': '710 - 2nd Av... \n", + "1 [{'description': 'Headquarters', 'address1': '... \n", + "2 [{'description': 'Headquarters', 'address1': '... \n", + "3 [{'description': None, 'address1': '135 Missis... \n", + "4 [{'description': 'Headquarters', 'address1': '... " + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = pd.DataFrame(al_menos_1_ofi)\n", + "data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(13744, 4)" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [], + "source": [ + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 13744/13744 [01:11<00:00, 192.60it/s]\n" + ] + } + ], + "source": [ + "lista_df=[] #ver de utilizar el coso de barras \n", + "\n", + "for i in tqdm(range(len(data.offices))):\n", + " test1 = pd.DataFrame(data.iloc[i].offices)\n", + " test1['name'] = str(data.loc[i,['name'][0]])\n", + " test1['total_employees'] = data.iloc[i].number_of_employees\n", + " test1['category'] = str(data.loc[i,['category_code'][0]])\n", + " test1['total_offices'] = len(data.iloc[i].offices)\n", + " lista_df.append(test1)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 225, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " description\n", + " address1\n", + " address2\n", + " zip_code\n", + " city\n", + " state_code\n", + " country_code\n", + " latitude\n", + " longitude\n", + " name\n", + " total_employees\n", + " category\n", + " total_offices\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " \n", + " 710 - 2nd Avenue\n", + " Suite 1100\n", + " 98104\n", + " Seattle\n", + " WA\n", + " USA\n", + " 47.6031\n", + " -122.333\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " \n", + " \n", + " 1\n", + " \n", + " 270 Lafayette Street\n", + " Suite 505\n", + " 10012\n", + " New York\n", + " NY\n", + " USA\n", + " 40.7237\n", + " -73.9964\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " \n", + " \n", + " 2\n", + " Headquarters\n", + " 4900 Hopyard Rd.\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.6929\n", + " -121.905\n", + " AdventNet\n", + " 600.0\n", + " enterprise\n", + " 1\n", + " \n", + " \n", + " 3\n", + " Headquarters\n", + " 4900 Hopyard Rd\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.6929\n", + " -121.905\n", + " Zoho\n", + " 1600.0\n", + " software\n", + " 1\n", + " \n", + " \n", + " 4\n", + " None\n", + " 135 Mississippi St\n", + " \n", + " 94107\n", + " San Francisco\n", + " CA\n", + " USA\n", + " 37.7647\n", + " -122.395\n", + " Digg\n", + " 60.0\n", + " news\n", + " 1\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " description address1 address2 zip_code city \\\n", + "0 710 - 2nd Avenue Suite 1100 98104 Seattle \n", + "1 270 Lafayette Street Suite 505 10012 New York \n", + "2 Headquarters 4900 Hopyard Rd. Suite 310 94588 Pleasanton \n", + "3 Headquarters 4900 Hopyard Rd Suite 310 94588 Pleasanton \n", + "4 None 135 Mississippi St 94107 San Francisco \n", + "\n", + " state_code country_code latitude longitude name total_employees \\\n", + "0 WA USA 47.6031 -122.333 Wetpaint 47.0 \n", + "1 NY USA 40.7237 -73.9964 Wetpaint 47.0 \n", + "2 CA USA 37.6929 -121.905 AdventNet 600.0 \n", + "3 CA USA 37.6929 -121.905 Zoho 1600.0 \n", + "4 CA USA 37.7647 -122.395 Digg 60.0 \n", + "\n", + " category total_offices \n", + "0 web 2 \n", + "1 web 2 \n", + "2 enterprise 1 \n", + "3 software 1 \n", + "4 news 1 " + ] + }, + "execution_count": 225, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final = pd.concat(lista_df).reset_index(drop=True)\n", + "final.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "country_code\n", + "USA 10229\n", + "GBR 1385\n", + "CAN 621\n", + "IND 519\n", + "DEU 407\n", + "FRA 375\n", + "AUS 272\n", + "ESP 240\n", + "ISR 239\n", + "CHN 209\n", + "Name: name, dtype: int64" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.groupby('country_code')['name'].count().sort_values(ascending=False).head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 16705/16705 [00:01<00:00, 13950.65it/s]\n" + ] + } + ], + "source": [ + "lista_x = []\n", + "for i in tqdm(range(len(final.longitude))):\n", + " \n", + " lista_x.append(dict({'type':'Point',\n", + " 'coordinates': [final.longitude[i],\n", + " final.latitude[i]]}))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 189, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 189, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(lista_x[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 190, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'Point', 'coordinates': [-122.333253, 47.603122]}\n", + "{'type': 'Point', 'coordinates': [-73.9964312, 40.7237306]}\n" + ] + } + ], + "source": [ + "for i in range(len(lista_x[0])):\n", + " print(lista_x[i])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 194, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 194, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(lista_x[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 196, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_values(['Point', [-122.333253, 47.603122]])" + ] + }, + "execution_count": 196, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lista_x[0].values()" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": {}, + "outputs": [], + "source": [ + "final['principal'] = pd.Series(lista_x)" + ] + }, + { + "cell_type": "code", + "execution_count": 193, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'type': 'Point', 'coordinates': [-122.173887, 37.480999]}" + ] + }, + "execution_count": 193, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(16705, 14)" + ] + }, + "execution_count": 178, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 211, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " description\n", + " address1\n", + " address2\n", + " zip_code\n", + " city\n", + " state_code\n", + " country_code\n", + " latitude\n", + " longitude\n", + " name\n", + " total_employees\n", + " category\n", + " total_offices\n", + " principal\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " \n", + " 710 - 2nd Avenue\n", + " Suite 1100\n", + " 98104\n", + " Seattle\n", + " WA\n", + " USA\n", + " 47.6031\n", + " -122.333\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-122.333253,...\n", + " \n", + " \n", + " 1\n", + " \n", + " 270 Lafayette Street\n", + " Suite 505\n", + " 10012\n", + " New York\n", + " NY\n", + " USA\n", + " 40.7237\n", + " -73.9964\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-73.9964312,...\n", + " \n", + " \n", + " 2\n", + " Headquarters\n", + " 4900 Hopyard Rd.\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.6929\n", + " -121.905\n", + " AdventNet\n", + " 600.0\n", + " enterprise\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-121.904945,...\n", + " \n", + " \n", + " 3\n", + " Headquarters\n", + " 4900 Hopyard Rd\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.6929\n", + " -121.905\n", + " Zoho\n", + " 1600.0\n", + " software\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-121.904945,...\n", + " \n", + " \n", + " 5\n", + " Headquarters\n", + " 1601 Willow Road\n", + " \n", + " 94025\n", + " Menlo Park\n", + " CA\n", + " USA\n", + " 37.416\n", + " -122.152\n", + " Facebook\n", + " 5299.0\n", + " social\n", + " 3\n", + " {'type': 'Point', 'coordinates': [-122.151801,...\n", + " \n", + " \n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " \n", + " \n", + " 16677\n", + " Corporate Headquarters\n", + " 2 Waters Park Drive, #250\n", + " \n", + " 94403\n", + " San Mateo\n", + " CA\n", + " USA\n", + " 37.5531\n", + " -122.302\n", + " NextLabs\n", + " 100.0\n", + " enterprise\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-122.301534,...\n", + " \n", + " \n", + " 16687\n", + " Headquarters\n", + " \n", + " \n", + " 89511\n", + " Reno\n", + " NV\n", + " USA\n", + " 39.3946\n", + " -119.812\n", + " MyChances\n", + " 2.0\n", + " consulting\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-119.8120795...\n", + " \n", + " \n", + " 16688\n", + " Menlo Park Office\n", + " \n", + " \n", + " 94025\n", + " Menlo Park\n", + " CA\n", + " USA\n", + " 37.4485\n", + " -122.18\n", + " MyChances\n", + " 2.0\n", + " consulting\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-122.1802812...\n", + " \n", + " \n", + " 16697\n", + " \n", + " 2401 East Katella Avenue\n", + " Suite 300\n", + " 92806-5909\n", + " Anaheim\n", + " CA\n", + " USA\n", + " 33.8065\n", + " -117.882\n", + " Willdan Group\n", + " 385.0\n", + " other\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-117.882314,...\n", + " \n", + " \n", + " 16699\n", + " \n", + " 400 Royal Palm Way\n", + " \n", + " 33480\n", + " Palm Beach\n", + " FL\n", + " USA\n", + " 26.7053\n", + " -80.0414\n", + " QSGI\n", + " 164.0\n", + " software\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-80.041395, ...\n", + " \n", + " \n", + "\n", + "3711 rows × 14 columns\n", + "" + ], + "text/plain": [ + " description address1 address2 \\\n", + "0 710 - 2nd Avenue Suite 1100 \n", + "1 270 Lafayette Street Suite 505 \n", + "2 Headquarters 4900 Hopyard Rd. Suite 310 \n", + "3 Headquarters 4900 Hopyard Rd Suite 310 \n", + "5 Headquarters 1601 Willow Road \n", + "... ... ... ... \n", + "16677 Corporate Headquarters 2 Waters Park Drive, #250 \n", + "16687 Headquarters \n", + "16688 Menlo Park Office \n", + "16697 2401 East Katella Avenue Suite 300 \n", + "16699 400 Royal Palm Way \n", + "\n", + " zip_code city state_code country_code latitude longitude \\\n", + "0 98104 Seattle WA USA 47.6031 -122.333 \n", + "1 10012 New York NY USA 40.7237 -73.9964 \n", + "2 94588 Pleasanton CA USA 37.6929 -121.905 \n", + "3 94588 Pleasanton CA USA 37.6929 -121.905 \n", + "5 94025 Menlo Park CA USA 37.416 -122.152 \n", + "... ... ... ... ... ... ... \n", + "16677 94403 San Mateo CA USA 37.5531 -122.302 \n", + "16687 89511 Reno NV USA 39.3946 -119.812 \n", + "16688 94025 Menlo Park CA USA 37.4485 -122.18 \n", + "16697 92806-5909 Anaheim CA USA 33.8065 -117.882 \n", + "16699 33480 Palm Beach FL USA 26.7053 -80.0414 \n", + "\n", + " name total_employees category total_offices \\\n", + "0 Wetpaint 47.0 web 2 \n", + "1 Wetpaint 47.0 web 2 \n", + "2 AdventNet 600.0 enterprise 1 \n", + "3 Zoho 1600.0 software 1 \n", + "5 Facebook 5299.0 social 3 \n", + "... ... ... ... ... \n", + "16677 NextLabs 100.0 enterprise 1 \n", + "16687 MyChances 2.0 consulting 2 \n", + "16688 MyChances 2.0 consulting 2 \n", + "16697 Willdan Group 385.0 other 1 \n", + "16699 QSGI 164.0 software 1 \n", + "\n", + " principal \n", + "0 {'type': 'Point', 'coordinates': [-122.333253,... \n", + "1 {'type': 'Point', 'coordinates': [-73.9964312,... \n", + "2 {'type': 'Point', 'coordinates': [-121.904945,... \n", + "3 {'type': 'Point', 'coordinates': [-121.904945,... \n", + "5 {'type': 'Point', 'coordinates': [-122.151801,... \n", + "... ... \n", + "16677 {'type': 'Point', 'coordinates': [-122.301534,... \n", + "16687 {'type': 'Point', 'coordinates': [-119.8120795... \n", + "16688 {'type': 'Point', 'coordinates': [-122.1802812... \n", + "16697 {'type': 'Point', 'coordinates': [-117.882314,... \n", + "16699 {'type': 'Point', 'coordinates': [-80.041395, ... \n", + "\n", + "[3711 rows x 14 columns]" + ] + }, + "execution_count": 211, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.dropna()" + ] + }, + { + "cell_type": "code", + "execution_count": 212, + "metadata": {}, + "outputs": [], + "source": [ + "final.to_json('oficinas.json') " + ] + }, + { + "cell_type": "code", + "execution_count": 213, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'/Users/EstebanCardona/Documents/IronHack/datamex0320/module-2/python-bi-project/python-bi-project - Esteban'" + ] + }, + "execution_count": 213, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 220, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 220, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db.first_officetest.insert_many(final.to_dict('records')) " + ] + }, + { + "cell_type": "code", + "execution_count": 222, + "metadata": {}, + "outputs": [ + { + "ename": "OperationFailure", + "evalue": "Can't extract geo keys: { _id: ObjectId('5e9b71b554d244e37a3cc54a'), description: \"\", address1: \"Suite 200\", address2: \"654 High Street\", zip_code: \"94301\", city: \"Palo Alto\", state_code: \"CA\", country_code: \"ISR\", latitude: null, longitude: null, name: \"Omnidrive\", total_employees: nan.0, category: \"network_hosting\", total_offices: 1, principal: { type: \"Point\", coordinates: [ null, null ] } } Point must only contain numeric elements", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mOperationFailure\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfirst_officetest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'principal'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'2dsphere'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36mcreate_index\u001b[0;34m(self, keys, session, **kwargs)\u001b[0m\n\u001b[1;32m 1993\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m\"maxTimeMS\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1994\u001b[0m \u001b[0mcmd_options\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"maxTimeMS\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"maxTimeMS\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1995\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__create_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mcmd_options\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1996\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1997\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36m__create_index\u001b[0;34m(self, keys, index_options, session, **kwargs)\u001b[0m\n\u001b[1;32m 1888\u001b[0m \u001b[0mcmd\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSON\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'createIndexes'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'indexes'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1889\u001b[0m \u001b[0mcmd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1890\u001b[0;31m self._command(\n\u001b[0m\u001b[1;32m 1891\u001b[0m \u001b[0msock_info\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcmd\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mread_preference\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mReadPreference\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPRIMARY\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1892\u001b[0m \u001b[0mcodec_options\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_UNICODE_REPLACE_CODEC_OPTIONS\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36m_command\u001b[0;34m(self, sock_info, command, slave_ok, read_preference, codec_options, check, allowable_errors, read_concern, write_concern, collation, session, retryable_write, user_fields)\u001b[0m\n\u001b[1;32m 233\u001b[0m \"\"\"\n\u001b[1;32m 234\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__database\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_tmp_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 235\u001b[0;31m return sock_info.command(\n\u001b[0m\u001b[1;32m 236\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__database\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 237\u001b[0m \u001b[0mcommand\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/pool.py\u001b[0m in \u001b[0;36mcommand\u001b[0;34m(self, dbname, spec, slave_ok, read_preference, codec_options, check, allowable_errors, check_keys, read_concern, write_concern, parse_write_concern_error, collation, session, client, retryable_write, publish_events, user_fields)\u001b[0m\n\u001b[1;32m 601\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_raise_if_not_writable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0munacknowledged\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 602\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 603\u001b[0;31m return command(self.sock, dbname, spec, slave_ok,\n\u001b[0m\u001b[1;32m 604\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_mongos\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mread_preference\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcodec_options\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 605\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcheck\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallowable_errors\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/network.py\u001b[0m in \u001b[0;36mcommand\u001b[0;34m(sock, dbname, spec, slave_ok, is_mongos, read_preference, codec_options, session, client, check, allowable_errors, address, check_keys, listeners, max_bson_size, read_concern, parse_write_concern_error, collation, compression_ctx, use_op_msg, unacknowledged, user_fields)\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse_doc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcheck\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 165\u001b[0;31m helpers._check_command_response(\n\u001b[0m\u001b[1;32m 166\u001b[0m \u001b[0mresponse_doc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallowable_errors\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m parse_write_concern_error=parse_write_concern_error)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/helpers.py\u001b[0m in \u001b[0;36m_check_command_response\u001b[0;34m(response, msg, allowable_errors, parse_write_concern_error)\u001b[0m\n\u001b[1;32m 157\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m\"%s\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 159\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mOperationFailure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0merrmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 160\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mOperationFailure\u001b[0m: Can't extract geo keys: { _id: ObjectId('5e9b71b554d244e37a3cc54a'), description: \"\", address1: \"Suite 200\", address2: \"654 High Street\", zip_code: \"94301\", city: \"Palo Alto\", state_code: \"CA\", country_code: \"ISR\", latitude: null, longitude: null, name: \"Omnidrive\", total_employees: nan.0, category: \"network_hosting\", total_offices: 1, principal: { type: \"Point\", coordinates: [ null, null ] } } Point must only contain numeric elements" + ] + } + ], + "source": [ + "db.first_officetest.create_index([('principal', '2dsphere')])" + ] + }, + { + "cell_type": "code", + "execution_count": 216, + "metadata": {}, + "outputs": [], + "source": [ + "cole = db.first_office" + ] + }, + { + "cell_type": "code", + "execution_count": 217, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " _id\n", + " description\n", + " address1\n", + " address2\n", + " zip_code\n", + " city\n", + " state_code\n", + " country_code\n", + " latitude\n", + " longitude\n", + " name\n", + " total_employees\n", + " category\n", + " total_offices\n", + " principal\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " 5e9b6c4d54d244e37a3c42c0\n", + " \n", + " 710 - 2nd Avenue\n", + " Suite 1100\n", + " 98104\n", + " Seattle\n", + " WA\n", + " USA\n", + " 47.603122\n", + " -122.333253\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-122.333253,...\n", + " \n", + " \n", + " 1\n", + " 5e9b6c4d54d244e37a3c42c1\n", + " \n", + " 270 Lafayette Street\n", + " Suite 505\n", + " 10012\n", + " New York\n", + " NY\n", + " USA\n", + " 40.723731\n", + " -73.996431\n", + " Wetpaint\n", + " 47.0\n", + " web\n", + " 2\n", + " {'type': 'Point', 'coordinates': [-73.9964312,...\n", + " \n", + " \n", + " 2\n", + " 5e9b6c4d54d244e37a3c42c2\n", + " Headquarters\n", + " 4900 Hopyard Rd.\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.692934\n", + " -121.904945\n", + " AdventNet\n", + " 600.0\n", + " enterprise\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-121.904945,...\n", + " \n", + " \n", + " 3\n", + " 5e9b6c4d54d244e37a3c42c3\n", + " Headquarters\n", + " 4900 Hopyard Rd\n", + " Suite 310\n", + " 94588\n", + " Pleasanton\n", + " CA\n", + " USA\n", + " 37.692934\n", + " -121.904945\n", + " Zoho\n", + " 1600.0\n", + " software\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-121.904945,...\n", + " \n", + " \n", + " 4\n", + " 5e9b6c4d54d244e37a3c42c4\n", + " None\n", + " 135 Mississippi St\n", + " \n", + " 94107\n", + " San Francisco\n", + " CA\n", + " USA\n", + " 37.764726\n", + " -122.394523\n", + " Digg\n", + " 60.0\n", + " news\n", + " 1\n", + " {'type': 'Point', 'coordinates': [-122.394523,...\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " _id description address1 address2 \\\n", + "0 5e9b6c4d54d244e37a3c42c0 710 - 2nd Avenue Suite 1100 \n", + "1 5e9b6c4d54d244e37a3c42c1 270 Lafayette Street Suite 505 \n", + "2 5e9b6c4d54d244e37a3c42c2 Headquarters 4900 Hopyard Rd. Suite 310 \n", + "3 5e9b6c4d54d244e37a3c42c3 Headquarters 4900 Hopyard Rd Suite 310 \n", + "4 5e9b6c4d54d244e37a3c42c4 None 135 Mississippi St \n", + "\n", + " zip_code city state_code country_code latitude longitude \\\n", + "0 98104 Seattle WA USA 47.603122 -122.333253 \n", + "1 10012 New York NY USA 40.723731 -73.996431 \n", + "2 94588 Pleasanton CA USA 37.692934 -121.904945 \n", + "3 94588 Pleasanton CA USA 37.692934 -121.904945 \n", + "4 94107 San Francisco CA USA 37.764726 -122.394523 \n", + "\n", + " name total_employees category total_offices \\\n", + "0 Wetpaint 47.0 web 2 \n", + "1 Wetpaint 47.0 web 2 \n", + "2 AdventNet 600.0 enterprise 1 \n", + "3 Zoho 1600.0 software 1 \n", + "4 Digg 60.0 news 1 \n", + "\n", + " principal \n", + "0 {'type': 'Point', 'coordinates': [-122.333253,... \n", + "1 {'type': 'Point', 'coordinates': [-73.9964312,... \n", + "2 {'type': 'Point', 'coordinates': [-121.904945,... \n", + "3 {'type': 'Point', 'coordinates': [-121.904945,... \n", + "4 {'type': 'Point', 'coordinates': [-122.394523,... " + ] + }, + "execution_count": 217, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pd.DataFrame(cole.find({})).head()" + ] + }, + { + "cell_type": "code", + "execution_count": 218, + "metadata": {}, + "outputs": [], + "source": [ + "def find_near(geopoint, radio=1000):\n", + " \n", + " return cole.find({'principal':{\n", + " '$near': {'$geometry': geopoint, '$maxDistance':radio}\n", + " }})\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 219, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":5: DeprecationWarning: count is deprecated. Use Collection.count_documents instead.\n", + " n_ofi=find_near(park_avenue, radio).count()\n" + ] + }, + { + "ename": "OperationFailure", + "evalue": "error processing query: ns=companies.first_officeTree: GEONEAR field=principal maxdist=1000 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error :: caused by :: unable to find index for $geoNear query", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mOperationFailure\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mradio\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1000\u001b[0m \u001b[0;31m# radio de busqueda\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mn_ofi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfind_near\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpark_avenue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mradio\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mn_ofi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/cursor.py\u001b[0m in \u001b[0;36mcount\u001b[0;34m(self, with_limit_and_skip)\u001b[0m\n\u001b[1;32m 784\u001b[0m \u001b[0mcmd\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"skip\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__skip\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 785\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 786\u001b[0;31m return self.__collection._count(\n\u001b[0m\u001b[1;32m 787\u001b[0m cmd, self.__collation, session=self.__session)\n\u001b[1;32m 788\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36m_count\u001b[0;34m(self, cmd, collation, session)\u001b[0m\n\u001b[1;32m 1597\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"n\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1598\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1599\u001b[0;31m return self.__database.client._retryable_read(\n\u001b[0m\u001b[1;32m 1600\u001b[0m _cmd, self._read_preference_for(session), session)\n\u001b[1;32m 1601\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/mongo_client.py\u001b[0m in \u001b[0;36m_retryable_read\u001b[0;34m(self, func, read_pref, session, address, retryable, exhaust)\u001b[0m\n\u001b[1;32m 1462\u001b[0m \u001b[0;31m# not support retryable reads, raise the last error.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1463\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mlast_error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1464\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msock_info\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslave_ok\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1465\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mServerSelectionTimeoutError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1466\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mretrying\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36m_cmd\u001b[0;34m(session, server, sock_info, slave_ok)\u001b[0m\n\u001b[1;32m 1584\u001b[0m \u001b[0;34m\"\"\"Internal count helper.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1585\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_cmd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msock_info\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslave_ok\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1586\u001b[0;31m res = self._command(\n\u001b[0m\u001b[1;32m 1587\u001b[0m \u001b[0msock_info\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1588\u001b[0m \u001b[0mcmd\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py\u001b[0m in \u001b[0;36m_command\u001b[0;34m(self, sock_info, command, slave_ok, read_preference, codec_options, check, allowable_errors, read_concern, write_concern, collation, session, retryable_write, user_fields)\u001b[0m\n\u001b[1;32m 233\u001b[0m \"\"\"\n\u001b[1;32m 234\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__database\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_tmp_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 235\u001b[0;31m return sock_info.command(\n\u001b[0m\u001b[1;32m 236\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__database\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 237\u001b[0m \u001b[0mcommand\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/pool.py\u001b[0m in \u001b[0;36mcommand\u001b[0;34m(self, dbname, spec, slave_ok, read_preference, codec_options, check, allowable_errors, check_keys, read_concern, write_concern, parse_write_concern_error, collation, session, client, retryable_write, publish_events, user_fields)\u001b[0m\n\u001b[1;32m 601\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_raise_if_not_writable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0munacknowledged\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 602\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 603\u001b[0;31m return command(self.sock, dbname, spec, slave_ok,\n\u001b[0m\u001b[1;32m 604\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_mongos\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mread_preference\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcodec_options\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 605\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcheck\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallowable_errors\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/network.py\u001b[0m in \u001b[0;36mcommand\u001b[0;34m(sock, dbname, spec, slave_ok, is_mongos, read_preference, codec_options, session, client, check, allowable_errors, address, check_keys, listeners, max_bson_size, read_concern, parse_write_concern_error, collation, compression_ctx, use_op_msg, unacknowledged, user_fields)\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_process_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse_doc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcheck\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 165\u001b[0;31m helpers._check_command_response(\n\u001b[0m\u001b[1;32m 166\u001b[0m \u001b[0mresponse_doc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallowable_errors\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m parse_write_concern_error=parse_write_concern_error)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/helpers.py\u001b[0m in \u001b[0;36m_check_command_response\u001b[0;34m(response, msg, allowable_errors, parse_write_concern_error)\u001b[0m\n\u001b[1;32m 157\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m\"%s\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 159\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mOperationFailure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0merrmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 160\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mOperationFailure\u001b[0m: error processing query: ns=companies.first_officeTree: GEONEAR field=principal maxdist=1000 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error :: caused by :: unable to find index for $geoNear query" + ] + } + ], + "source": [ + "park_avenue={'type': 'Point', 'coordinates':[-73.9964312, 40.7237306]} # geopoint\n", + "\n", + "radio=1000 # radio de busqueda\n", + "\n", + "n_ofi=find_near(park_avenue, radio).count()\n", + "\n", + "n_ofi" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "ename": "GeocoderServiceError", + "evalue": "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mSSLCertVerificationError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mdo_open\u001b[0;34m(self, http_class, req, **http_conn_args)\u001b[0m\n\u001b[1;32m 1316\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1317\u001b[0;31m h.request(req.get_method(), req.selector, req.data, headers,\n\u001b[0m\u001b[1;32m 1318\u001b[0m encode_chunked=req.has_header('Transfer-encoding'))\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1229\u001b[0m \u001b[0;34m\"\"\"Send a complete request to the server.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1230\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_send_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1231\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36m_send_request\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1275\u001b[0m \u001b[0mbody\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_encode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'body'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1276\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mendheaders\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1277\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mendheaders\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1224\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mCannotSendHeader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1225\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_send_output\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage_body\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1226\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36m_send_output\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1003\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_buffer\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1004\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1005\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 943\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mauto_open\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 944\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 945\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mconnect\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1399\u001b[0;31m self.sock = self._context.wrap_socket(self.sock,\n\u001b[0m\u001b[1;32m 1400\u001b[0m server_hostname=server_hostname)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36mwrap_socket\u001b[0;34m(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)\u001b[0m\n\u001b[1;32m 499\u001b[0m \u001b[0;31m# ctx._wrap_socket()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 500\u001b[0;31m return self.sslsocket_class._create(\n\u001b[0m\u001b[1;32m 501\u001b[0m \u001b[0msock\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msock\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36m_create\u001b[0;34m(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)\u001b[0m\n\u001b[1;32m 1039\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"do_handshake_on_connect should not be specified for non-blocking sockets\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1040\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdo_handshake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1041\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mOSError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36mdo_handshake\u001b[0;34m(self, block)\u001b[0m\n\u001b[1;32m 1308\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msettimeout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1309\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdo_handshake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1310\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mSSLCertVerificationError\u001b[0m: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mURLError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/base.py\u001b[0m in \u001b[0;36m_call_geocoder\u001b[0;34m(self, url, timeout, raw, requester, deserializer, **kwargs)\u001b[0m\n\u001b[1;32m 354\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 355\u001b[0;31m \u001b[0mpage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequester\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 356\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[1;32m 524\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maudit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'urllib.Request'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 525\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_open\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 526\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m_open\u001b[0;34m(self, req, data)\u001b[0m\n\u001b[1;32m 541\u001b[0m \u001b[0mprotocol\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 542\u001b[0;31m result = self._call_chain(self.handle_open, protocol, protocol +\n\u001b[0m\u001b[1;32m 543\u001b[0m '_open', req)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m_call_chain\u001b[0;34m(self, chain, kind, meth_name, *args)\u001b[0m\n\u001b[1;32m 501\u001b[0m \u001b[0mfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhandler\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 502\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 503\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mhttps_open\u001b[0;34m(self, req)\u001b[0m\n\u001b[1;32m 1359\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mhttps_open\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1360\u001b[0;31m return self.do_open(http.client.HTTPSConnection, req,\n\u001b[0m\u001b[1;32m 1361\u001b[0m context=self._context, check_hostname=self._check_hostname)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mdo_open\u001b[0;34m(self, http_class, req, **http_conn_args)\u001b[0m\n\u001b[1;32m 1319\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# timeout error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1320\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mURLError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1321\u001b[0m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mURLError\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mGeocoderServiceError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mgeolocator\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNominatim\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muser_agent\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'teburgr_app'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mlocation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgeolocator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeocode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"175 5th Avenue NYC\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mlocation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/osm.py\u001b[0m in \u001b[0;36mgeocode\u001b[0;34m(self, query, exactly_one, timeout, limit, addressdetails, language, geometry, extratags, country_codes, viewbox, bounded, featuretype, namedetails)\u001b[0m\n\u001b[1;32m 404\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 405\u001b[0m return self._parse_json(\n\u001b[0;32m--> 406\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_geocoder\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexactly_one\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 407\u001b[0m )\n\u001b[1;32m 408\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/base.py\u001b[0m in \u001b[0;36m_call_geocoder\u001b[0;34m(self, url, timeout, raw, requester, deserializer, **kwargs)\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m\"timed out\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mGeocoderTimedOut\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Service timed out'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mGeocoderServiceError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'getcode'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mGeocoderServiceError\u001b[0m: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)" + ] + } + ], + "source": [ + "from geopy.geocoders import Nominatim\n", + "import certifi\n", + "\n", + "geolocator = Nominatim(user_agent='teburgr_app')\n", + "\n", + "location = geolocator.geocode(\"175 5th Avenue NYC\")\n", + "\n", + "location" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "ename": "GeocoderServiceError", + "evalue": "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mSSLCertVerificationError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mdo_open\u001b[0;34m(self, http_class, req, **http_conn_args)\u001b[0m\n\u001b[1;32m 1316\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1317\u001b[0;31m h.request(req.get_method(), req.selector, req.data, headers,\n\u001b[0m\u001b[1;32m 1318\u001b[0m encode_chunked=req.has_header('Transfer-encoding'))\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1229\u001b[0m \u001b[0;34m\"\"\"Send a complete request to the server.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1230\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_send_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1231\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36m_send_request\u001b[0;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[1;32m 1275\u001b[0m \u001b[0mbody\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_encode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'body'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1276\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mendheaders\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1277\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mendheaders\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1224\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mCannotSendHeader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1225\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_send_output\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage_body\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencode_chunked\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mencode_chunked\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1226\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36m_send_output\u001b[0;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[1;32m 1003\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_buffer\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1004\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1005\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36msend\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 943\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mauto_open\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 944\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 945\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py\u001b[0m in \u001b[0;36mconnect\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1399\u001b[0;31m self.sock = self._context.wrap_socket(self.sock,\n\u001b[0m\u001b[1;32m 1400\u001b[0m server_hostname=server_hostname)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36mwrap_socket\u001b[0;34m(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)\u001b[0m\n\u001b[1;32m 499\u001b[0m \u001b[0;31m# ctx._wrap_socket()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 500\u001b[0;31m return self.sslsocket_class._create(\n\u001b[0m\u001b[1;32m 501\u001b[0m \u001b[0msock\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msock\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36m_create\u001b[0;34m(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)\u001b[0m\n\u001b[1;32m 1039\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"do_handshake_on_connect should not be specified for non-blocking sockets\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1040\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdo_handshake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1041\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mOSError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py\u001b[0m in \u001b[0;36mdo_handshake\u001b[0;34m(self, block)\u001b[0m\n\u001b[1;32m 1308\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msettimeout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1309\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdo_handshake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1310\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mSSLCertVerificationError\u001b[0m: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mURLError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/base.py\u001b[0m in \u001b[0;36m_call_geocoder\u001b[0;34m(self, url, timeout, raw, requester, deserializer, **kwargs)\u001b[0m\n\u001b[1;32m 354\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 355\u001b[0;31m \u001b[0mpage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequester\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 356\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[1;32m 524\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maudit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'urllib.Request'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 525\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_open\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 526\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m_open\u001b[0;34m(self, req, data)\u001b[0m\n\u001b[1;32m 541\u001b[0m \u001b[0mprotocol\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 542\u001b[0;31m result = self._call_chain(self.handle_open, protocol, protocol +\n\u001b[0m\u001b[1;32m 543\u001b[0m '_open', req)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m_call_chain\u001b[0;34m(self, chain, kind, meth_name, *args)\u001b[0m\n\u001b[1;32m 501\u001b[0m \u001b[0mfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhandler\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmeth_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 502\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 503\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mhttps_open\u001b[0;34m(self, req)\u001b[0m\n\u001b[1;32m 1359\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mhttps_open\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreq\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1360\u001b[0;31m return self.do_open(http.client.HTTPSConnection, req,\n\u001b[0m\u001b[1;32m 1361\u001b[0m context=self._context, check_hostname=self._check_hostname)\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mdo_open\u001b[0;34m(self, http_class, req, **http_conn_args)\u001b[0m\n\u001b[1;32m 1319\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# timeout error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1320\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mURLError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1321\u001b[0m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mh\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mURLError\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mGeocoderServiceError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlocation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgeolocator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeocode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"175 5th Avenue NYC\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/osm.py\u001b[0m in \u001b[0;36mgeocode\u001b[0;34m(self, query, exactly_one, timeout, limit, addressdetails, language, geometry, extratags, country_codes, viewbox, bounded, featuretype, namedetails)\u001b[0m\n\u001b[1;32m 404\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 405\u001b[0m return self._parse_json(\n\u001b[0;32m--> 406\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_geocoder\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexactly_one\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 407\u001b[0m )\n\u001b[1;32m 408\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopy/geocoders/base.py\u001b[0m in \u001b[0;36m_call_geocoder\u001b[0;34m(self, url, timeout, raw, requester, deserializer, **kwargs)\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m\"timed out\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mGeocoderTimedOut\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Service timed out'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mGeocoderServiceError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'getcode'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mGeocoderServiceError\u001b[0m: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)" + ] + } + ], + "source": [ + "location = geolocator.geocode(\"175 5th Avenue NYC\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.8.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/module-2/python-bi-project/python-bi-project - Esteban/geocoder testing.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/geocoder testing.ipynb new file mode 100644 index 0000000..e656f10 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/geocoder testing.ipynb @@ -0,0 +1,1136 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "from pygeocoder import Geocoder\n", + "import pandas as pd\n", + "import numpy as np\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "ename": "GeocoderError", + "evalue": "Error REQUEST_DENIED\nQuery: https://maps.google.com/maps/api/geocode/json?address=4207+N+Washington+Ave%2C+Douglas%2C+AZ+85607&sensor=false&bounds=®ion=&language=&components=", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mGeocoderError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mGeocoder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeocode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"4207 N Washington Ave, Douglas, AZ 85607\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalid_address\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pygeocoder.py\u001b[0m in \u001b[0;36mgeocode\u001b[0;34m(self, address, sensor, bounds, region, language, components)\u001b[0m\n\u001b[1;32m 127\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mGeocoderResult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 129\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mGeocoderResult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mGeocoder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 130\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 131\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0momnimethod\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pygeocoder.py\u001b[0m in \u001b[0;36mget_data\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m 210\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 211\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'status'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mGeocoderError\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mG_GEO_OK\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 212\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mGeocoderError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse_json\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'status'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 213\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresponse_json\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'results'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 214\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mGeocoderError\u001b[0m: Error REQUEST_DENIED\nQuery: https://maps.google.com/maps/api/geocode/json?address=4207+N+Washington+Ave%2C+Douglas%2C+AZ+85607&sensor=false&bounds=®ion=&language=&components=" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting opencage\n", + " Downloading opencage-1.2-py3-none-any.whl (5.6 kB)\n", + "Requirement already satisfied: six>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from opencage) (1.14.0)\n", + "Requirement already satisfied: Requests>=2.2.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from opencage) (2.23.0)\n", + "Requirement already satisfied: chardet<4,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Requests>=2.2.0->opencage) (3.0.4)\n", + "Requirement already satisfied: idna<3,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Requests>=2.2.0->opencage) (2.9)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Requests>=2.2.0->opencage) (2020.4.5.1)\n", + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Requests>=2.2.0->opencage) (1.25.8)\n", + "Installing collected packages: opencage\n", + "Successfully installed opencage-1.2\n" + ] + } + ], + "source": [ + "!pip3 install opencage" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "from opencage.geocoder import OpenCageGeocode\n", + "\n", + "\n", + "key = 'd8314354b31d46a298e0f21ffb920a34'\n", + "geocoder = OpenCageGeocode(key)\n", + "\n", + "results = geocoder.reverse_geocode(44.8303087, -0.5761911)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(results)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['annotations', 'bounds', 'components', 'confidence', 'formatted', 'geometry'])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results[0].keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'annotations': {'DMS': {'lat': \"44° 49' 49.11132'' N\",\n", + " 'lng': \"0° 34' 34.28796'' E\"},\n", + " 'MGRS': '30TXQ9159666958',\n", + " 'Maidenhead': 'IN94rt09ug',\n", + " 'Mercator': {'x': -64141.3, 'y': 5564710.789},\n", + " 'OSM': {'edit_url': 'https://www.openstreetmap.org/edit?node=2754853042#map=16/44.83031/-0.57619',\n", + " 'note_url': 'https://www.openstreetmap.org/note/new#map=16/44.83031/-0.57619&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=44.83031&mlon=-0.57619#map=16/44.83031/-0.57619'},\n", + " 'UN_M49': {'regions': {'EUROPE': '150',\n", + " 'FR': '250',\n", + " 'WESTERN_EUROPE': '155',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 33,\n", + " 'currency': {'alternate_symbols': [],\n", + " 'decimal_mark': ',',\n", + " 'html_entity': '€',\n", + " 'iso_code': 'EUR',\n", + " 'iso_numeric': '978',\n", + " 'name': 'Euro',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '€',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': '.'},\n", + " 'flag': '🇫🇷',\n", + " 'geohash': 'ezzx4ch7mz0zbyftcpdf',\n", + " 'qibla': 111.75,\n", + " 'roadinfo': {'drive_on': 'right',\n", + " 'road': 'Rue Sauteyron',\n", + " 'speed_in': 'km/h'},\n", + " 'sun': {'rise': {'apparent': 1587273120,\n", + " 'astronomical': 1587266580,\n", + " 'civil': 1587271260,\n", + " 'nautical': 1587268980},\n", + " 'set': {'apparent': 1587322320,\n", + " 'astronomical': 1587328860,\n", + " 'civil': 1587324180,\n", + " 'nautical': 1587326460}},\n", + " 'timezone': {'name': 'Europe/Paris',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': 7200,\n", + " 'offset_string': '+0200',\n", + " 'short_name': 'CEST'},\n", + " 'what3words': {'words': 'advice.quiet.surveyed'}},\n", + " 'bounds': {'northeast': {'lat': 44.8304087, 'lng': -0.5760911},\n", + " 'southwest': {'lat': 44.8302087, 'lng': -0.5762911}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'FR',\n", + " 'ISO_3166-1_alpha-3': 'FRA',\n", + " '_category': 'building',\n", + " '_type': 'building',\n", + " 'city': 'Bordeaux',\n", + " 'continent': 'Europe',\n", + " 'country': 'France',\n", + " 'country_code': 'fr',\n", + " 'county': 'Bordeaux',\n", + " 'house_number': '11',\n", + " 'political_union': 'European Union',\n", + " 'postcode': '33000',\n", + " 'road': 'Rue Sauteyron',\n", + " 'state': 'New Aquitaine',\n", + " 'state_district': 'Gironde',\n", + " 'suburb': 'Bordeaux Sud'},\n", + " 'confidence': 10,\n", + " 'formatted': '11 Rue Sauteyron, 33000 Bordeaux, France',\n", + " 'geometry': {'lat': 44.8303087, 'lng': -0.5761911}}]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'OpenCageGeocode' object is not callable", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgeocoder\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'175 5th Avenue NYC'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: 'OpenCageGeocode' object is not callable" + ] + } + ], + "source": [ + "results = geocoder('175 5th Avenue NYC')\n", + "results" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'annotations': {'DMS': {'lat': \"40° 44' 27.81312'' N\",\n", + " 'lng': \"73° 59' 22.70976'' W\"},\n", + " 'FIPS': {'county': '36061', 'state': '36'},\n", + " 'MGRS': '18TWL8530510503',\n", + " 'Maidenhead': 'FN30ar17fu',\n", + " 'Mercator': {'x': -8236489.229, 'y': 4946329.848},\n", + " 'OSM': {'edit_url': 'https://www.openstreetmap.org/edit?way=264768896#map=16/40.74106/-73.98964',\n", + " 'note_url': 'https://www.openstreetmap.org/note/new#map=16/40.74106/-73.98964&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=40.74106&mlon=-73.98964#map=16/40.74106/-73.98964'},\n", + " 'UN_M49': {'regions': {'AMERICAS': '019',\n", + " 'NORTHERN_AMERICA': '021',\n", + " 'US': '840',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 1,\n", + " 'currency': {'alternate_symbols': ['US$'],\n", + " 'decimal_mark': '.',\n", + " 'disambiguate_symbol': 'US$',\n", + " 'html_entity': '$',\n", + " 'iso_code': 'USD',\n", + " 'iso_numeric': '840',\n", + " 'name': 'United States Dollar',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '$',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': ','},\n", + " 'flag': '🇺🇸',\n", + " 'geohash': 'dr5ru2dmu7ukx328qsw0',\n", + " 'qibla': 58.49,\n", + " 'roadinfo': {'drive_on': 'right', 'road': '5th Avenue', 'speed_in': 'mph'},\n", + " 'sun': {'rise': {'apparent': 1587291060,\n", + " 'astronomical': 1587285120,\n", + " 'civil': 1587289380,\n", + " 'nautical': 1587287280},\n", + " 'set': {'apparent': 1587339540,\n", + " 'astronomical': 1587259140,\n", + " 'civil': 1587254880,\n", + " 'nautical': 1587256980}},\n", + " 'timezone': {'name': 'America/New_York',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': -14400,\n", + " 'offset_string': '-0400',\n", + " 'short_name': 'EDT'},\n", + " 'what3words': {'words': 'news.lung.bossy'},\n", + " 'wikidata': 'Q220728'},\n", + " 'bounds': {'northeast': {'lat': 40.7413004, 'lng': -73.9895014},\n", + " 'southwest': {'lat': 40.7407597, 'lng': -73.9898715}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'travel/tourism',\n", + " '_type': 'attraction',\n", + " 'attraction': 'Flatiron Building',\n", + " 'city': 'New York',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'New York County',\n", + " 'house_number': '175',\n", + " 'postcode': '10010',\n", + " 'road': '5th Avenue',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY',\n", + " 'suburb': 'Manhattan'},\n", + " 'confidence': 9,\n", + " 'formatted': 'Flatiron Building, 175 5th Avenue, New York, NY 10010, United States of America',\n", + " 'geometry': {'lat': 40.7410592, 'lng': -73.9896416}},\n", + " {'annotations': {'DMS': {'lat': \"40° 44' 27.85992'' N\",\n", + " 'lng': \"73° 59' 22.75224'' W\"},\n", + " 'FIPS': {'county': '36061', 'state': '36'},\n", + " 'MGRS': '18TWL8530410505',\n", + " 'Maidenhead': 'FN30ar17fu',\n", + " 'Mercator': {'x': -8236490.54, 'y': 4946331.751},\n", + " 'OSM': {'edit_url': 'https://www.openstreetmap.org/edit?node=2517056822#map=16/40.74107/-73.98965',\n", + " 'note_url': 'https://www.openstreetmap.org/note/new#map=16/40.74107/-73.98965&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=40.74107&mlon=-73.98965#map=16/40.74107/-73.98965'},\n", + " 'UN_M49': {'regions': {'AMERICAS': '019',\n", + " 'NORTHERN_AMERICA': '021',\n", + " 'US': '840',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 1,\n", + " 'currency': {'alternate_symbols': ['US$'],\n", + " 'decimal_mark': '.',\n", + " 'disambiguate_symbol': 'US$',\n", + " 'html_entity': '$',\n", + " 'iso_code': 'USD',\n", + " 'iso_numeric': '840',\n", + " 'name': 'United States Dollar',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '$',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': ','},\n", + " 'flag': '🇺🇸',\n", + " 'geohash': 'dr5ru2dmun7dn4zctf59',\n", + " 'qibla': 58.49,\n", + " 'roadinfo': {'drive_on': 'right', 'road': '5th Avenue', 'speed_in': 'mph'},\n", + " 'sun': {'rise': {'apparent': 1587291060,\n", + " 'astronomical': 1587285120,\n", + " 'civil': 1587289380,\n", + " 'nautical': 1587287280},\n", + " 'set': {'apparent': 1587339540,\n", + " 'astronomical': 1587259140,\n", + " 'civil': 1587254880,\n", + " 'nautical': 1587256980}},\n", + " 'timezone': {'name': 'America/New_York',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': -14400,\n", + " 'offset_string': '-0400',\n", + " 'short_name': 'EDT'},\n", + " 'what3words': {'words': 'mute.liver.spoke'},\n", + " 'wikidata': 'Q1427377'},\n", + " 'bounds': {'northeast': {'lat': 40.7411222, 'lng': -73.9896034},\n", + " 'southwest': {'lat': 40.7410222, 'lng': -73.9897034}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'travel/tourism',\n", + " '_type': 'attraction',\n", + " 'attraction': 'Flatiron District',\n", + " 'city': 'New York',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'New York County',\n", + " 'house_number': '175',\n", + " 'postcode': '10010',\n", + " 'road': '5th Avenue',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY',\n", + " 'suburb': 'Manhattan'},\n", + " 'confidence': 9,\n", + " 'formatted': 'Flatiron District, 175 5th Avenue, New York, NY 10010, United States of America',\n", + " 'geometry': {'lat': 40.7410722, 'lng': -73.9896534}},\n", + " {'annotations': {'DMS': {'lat': \"40° 40' 38.10144'' N\",\n", + " 'lng': \"73° 58' 46.65180'' W\"},\n", + " 'FIPS': {'county': '36047', 'state': '36'},\n", + " 'MGRS': '18TWL8623203430',\n", + " 'Maidenhead': 'FN30aq22km',\n", + " 'Mercator': {'x': -8235374.234, 'y': 4936995.433},\n", + " 'OSM': {'edit_url': 'https://www.openstreetmap.org/edit?way=250014491#map=16/40.67725/-73.97963',\n", + " 'note_url': 'https://www.openstreetmap.org/note/new#map=16/40.67725/-73.97963&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=40.67725&mlon=-73.97963#map=16/40.67725/-73.97963'},\n", + " 'UN_M49': {'regions': {'AMERICAS': '019',\n", + " 'NORTHERN_AMERICA': '021',\n", + " 'US': '840',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 1,\n", + " 'currency': {'alternate_symbols': ['US$'],\n", + " 'decimal_mark': '.',\n", + " 'disambiguate_symbol': 'US$',\n", + " 'html_entity': '$',\n", + " 'iso_code': 'USD',\n", + " 'iso_numeric': '840',\n", + " 'name': 'United States Dollar',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '$',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': ','},\n", + " 'flag': '🇺🇸',\n", + " 'geohash': 'dr5rkt1djv11fmw94014',\n", + " 'qibla': 58.5,\n", + " 'roadinfo': {'drive_on': 'right', 'road': '5th Avenue', 'speed_in': 'mph'},\n", + " 'sun': {'rise': {'apparent': 1587291060,\n", + " 'astronomical': 1587285120,\n", + " 'civil': 1587289380,\n", + " 'nautical': 1587287280},\n", + " 'set': {'apparent': 1587339540,\n", + " 'astronomical': 1587259140,\n", + " 'civil': 1587254880,\n", + " 'nautical': 1587256920}},\n", + " 'timezone': {'name': 'America/New_York',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': -14400,\n", + " 'offset_string': '-0400',\n", + " 'short_name': 'EDT'},\n", + " 'what3words': {'words': 'values.bills.part'}},\n", + " 'bounds': {'northeast': {'lat': 40.6773242, 'lng': -73.979504},\n", + " 'southwest': {'lat': 40.6771765, 'lng': -73.9797469}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'place_of_worship',\n", + " '_type': 'place_of_worship',\n", + " 'city': 'New York',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'Kings County',\n", + " 'house_number': '175',\n", + " 'neighbourhood': 'Park Slope',\n", + " 'place_of_worship': 'Iglesia Pentecostal De Jesu Cristo',\n", + " 'postcode': '11217',\n", + " 'road': '5th Avenue',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY',\n", + " 'suburb': 'Brooklyn'},\n", + " 'confidence': 9,\n", + " 'formatted': 'Iglesia Pentecostal De Jesu Cristo, 175 5th Avenue, New York, NY 11217, United States of America',\n", + " 'geometry': {'lat': 40.6772504, 'lng': -73.9796255}},\n", + " {'annotations': {'DMS': {'lat': \"40° 44' 27.95208'' N\",\n", + " 'lng': \"73° 59' 23.00856'' W\"},\n", + " 'FIPS': {'county': '36061', 'state': '36'},\n", + " 'MGRS': '18TWL8529710507',\n", + " 'Maidenhead': 'FN30ar17fu',\n", + " 'Mercator': {'x': -8236498.466, 'y': 4946335.498},\n", + " 'OSM': {'edit_url': 'https://www.openstreetmap.org/edit?node=7139825363#map=16/40.74110/-73.98972',\n", + " 'note_url': 'https://www.openstreetmap.org/note/new#map=16/40.74110/-73.98972&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=40.74110&mlon=-73.98972#map=16/40.74110/-73.98972'},\n", + " 'UN_M49': {'regions': {'AMERICAS': '019',\n", + " 'NORTHERN_AMERICA': '021',\n", + " 'US': '840',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 1,\n", + " 'currency': {'alternate_symbols': ['US$'],\n", + " 'decimal_mark': '.',\n", + " 'disambiguate_symbol': 'US$',\n", + " 'html_entity': '$',\n", + " 'iso_code': 'USD',\n", + " 'iso_numeric': '840',\n", + " 'name': 'United States Dollar',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '$',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': ','},\n", + " 'flag': '🇺🇸',\n", + " 'geohash': 'dr5ru2dq47ndg3e0w1sk',\n", + " 'qibla': 58.49,\n", + " 'roadinfo': {'drive_on': 'right', 'road': '5th Avenue', 'speed_in': 'mph'},\n", + " 'sun': {'rise': {'apparent': 1587291060,\n", + " 'astronomical': 1587285120,\n", + " 'civil': 1587289380,\n", + " 'nautical': 1587287280},\n", + " 'set': {'apparent': 1587339540,\n", + " 'astronomical': 1587259140,\n", + " 'civil': 1587254880,\n", + " 'nautical': 1587256980}},\n", + " 'timezone': {'name': 'America/New_York',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': -14400,\n", + " 'offset_string': '-0400',\n", + " 'short_name': 'EDT'},\n", + " 'what3words': {'words': 'fits.lime.trying'}},\n", + " 'bounds': {'northeast': {'lat': 40.7411478, 'lng': -73.9896746},\n", + " 'southwest': {'lat': 40.7410478, 'lng': -73.9897746}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'building',\n", + " '_type': 'building',\n", + " 'city': 'New York',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'New York County',\n", + " 'house_number': '175',\n", + " 'postcode': '10035',\n", + " 'road': '5th Avenue',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY',\n", + " 'suburb': 'Manhattan'},\n", + " 'confidence': 10,\n", + " 'formatted': '175 5th Avenue, New York, NY 10035, United States of America',\n", + " 'geometry': {'lat': 40.7410978, 'lng': -73.9897246}},\n", + " {'annotations': {'DMS': {'lat': \"40° 46' 17.29200'' N\",\n", + " 'lng': \"73° 58' 3.79200'' W\"},\n", + " 'FIPS': {'county': '36061', 'state': '36'},\n", + " 'MGRS': '18TWL8711613901',\n", + " 'Maidenhead': 'FN30as35ud',\n", + " 'Mercator': {'x': -8234048.926, 'y': 4950781.733},\n", + " 'OSM': {'note_url': 'https://www.openstreetmap.org/note/new#map=16/40.77147/-73.96772&layers=N',\n", + " 'url': 'https://www.openstreetmap.org/?mlat=40.77147&mlon=-73.96772#map=16/40.77147/-73.96772'},\n", + " 'UN_M49': {'regions': {'AMERICAS': '019',\n", + " 'NORTHERN_AMERICA': '021',\n", + " 'US': '840',\n", + " 'WORLD': '001'},\n", + " 'statistical_groupings': ['MEDC']},\n", + " 'callingcode': 1,\n", + " 'currency': {'alternate_symbols': ['US$'],\n", + " 'decimal_mark': '.',\n", + " 'disambiguate_symbol': 'US$',\n", + " 'html_entity': '$',\n", + " 'iso_code': 'USD',\n", + " 'iso_numeric': '840',\n", + " 'name': 'United States Dollar',\n", + " 'smallest_denomination': 1,\n", + " 'subunit': 'Cent',\n", + " 'subunit_to_unit': 100,\n", + " 'symbol': '$',\n", + " 'symbol_first': 1,\n", + " 'thousands_separator': ','},\n", + " 'flag': '🇺🇸',\n", + " 'geohash': 'dr5ruy4r50ykj8cu4xjv',\n", + " 'qibla': 58.51,\n", + " 'roadinfo': {'drive_on': 'right', 'speed_in': 'mph'},\n", + " 'sun': {'rise': {'apparent': 1587291060,\n", + " 'astronomical': 1587285060,\n", + " 'civil': 1587289320,\n", + " 'nautical': 1587287280},\n", + " 'set': {'apparent': 1587339540,\n", + " 'astronomical': 1587259140,\n", + " 'civil': 1587254880,\n", + " 'nautical': 1587256980}},\n", + " 'timezone': {'name': 'America/New_York',\n", + " 'now_in_dst': 1,\n", + " 'offset_sec': -14400,\n", + " 'offset_string': '-0400',\n", + " 'short_name': 'EDT'},\n", + " 'what3words': {'words': 'reader.packet.pitch'}},\n", + " 'components': {'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'place',\n", + " '_type': 'county',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'New York',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY'},\n", + " 'confidence': 9,\n", + " 'formatted': 'New York, NY, United States of America',\n", + " 'geometry': {'lat': 40.77147, 'lng': -73.96772}}]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "query = '175 5th Avenue NYC'\n", + "results = geocoder.geocode(query)\n", + "results" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40.7410592 -73.9896416\n" + ] + } + ], + "source": [ + "print(results[0]['geometry']['lat'], results[0]['geometry']['lng'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'🇺🇸'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results[0]['annotations']['flag']" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "def getting_coor():\n", + " try:\n", + " x = input('Where would you like your office? ')\n", + " results = geocoder.geocode(x)\n", + " coordinates=[]\n", + " coordinates.append(results[0]['geometry']['lat']) \n", + " coordinates.append(results[0]['geometry']['lng'])\n", + " coordinates.append(results[0]['annotations']['flag'])\n", + " return coordinates\n", + " except:\n", + " return 'Not a valid address'" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "def getting_coor():\n", + " try:\n", + " x = input('Where would you like your office? ')\n", + " results = geocoder.geocode(x)\n", + " coordinates=[]\n", + " coordinates.append(results[0]['geometry']['lat']) \n", + " coordinates.append(results[0]['geometry']['lng'])\n", + " country = results[0]['annotations']['flag']\n", + " return list(coordinates,country)\n", + " except:\n", + " return 'Not a valid address'" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? avenida sonora 113 roma norte\n" + ] + }, + { + "data": { + "text/plain": [ + "'Not a valid address'" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getting_coor()" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "def getting_coor():\n", + " try:\n", + " x = input('Where would you like your office? ')\n", + " results = geocoder.geocode(x)\n", + " fcoordinates=[]\n", + " coordinates=[]\n", + " coordinates.append(results[0]['geometry']['lng'])\n", + " coordinates.append(results[0]['geometry']['lat']) \n", + " country = results[0]['annotations']['flag']\n", + " fcoordinates.append(coordinates)\n", + " fcoordinates.append(country)\n", + " return fcoordinates\n", + " except:\n", + " return 'Not a valid address'\n" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? avenida sonora 113\n" + ] + }, + { + "data": { + "text/plain": [ + "[-99.1711985, 19.4173531]" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getting_coor()[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "results = geocoder.geocode(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['annotations', 'bounds', 'components', 'confidence', 'formatted', 'geometry'])" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results[0].keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'ISO_3166-1_alpha-2': 'MX',\n", + " 'ISO_3166-1_alpha-3': 'MEX',\n", + " '_category': 'road',\n", + " '_type': 'road',\n", + " 'city': 'Mexico City',\n", + " 'continent': 'North America',\n", + " 'country': 'Mexico',\n", + " 'country_code': 'mx',\n", + " 'county': 'Cuauhtémoc',\n", + " 'neighbourhood': 'Condesa',\n", + " 'postcode': '06140',\n", + " 'road': 'Avenida Sonora',\n", + " 'road_type': 'tertiary',\n", + " 'state': 'Mexico City'}" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results[0]['components']" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'neighbourhood'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mcity\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'city'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mcounty\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'county'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mnei\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'neighbourhood'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mlocalidad\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcountry\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mcity\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mcounty\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mnei\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: 'neighbourhood'" + ] + } + ], + "source": [ + "country = results[0]['components']['country']\n", + "city=results[0]['components']['city']\n", + "county = results[0]['components']['county']\n", + "nei = results[0]['components']['neighbourhood']\n", + "\n", + "localidad = country+', '+city+', '+county+', '+nei\n", + "localidad" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'ISO_3166-1_alpha-2': 'US',\n", + " 'ISO_3166-1_alpha-3': 'USA',\n", + " '_category': 'outdoors/recreation',\n", + " '_type': 'park',\n", + " 'city': 'New York',\n", + " 'continent': 'North America',\n", + " 'country': 'United States of America',\n", + " 'country_code': 'us',\n", + " 'county': 'New York County',\n", + " 'park': 'Central Park',\n", + " 'state': 'New York',\n", + " 'state_code': 'NY',\n", + " 'suburb': 'Manhattan'}" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nei = results[0]['components']\n", + "nei" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? central park\n", + "Whats the max distance you would like to evaluate: 4000\n" + ] + }, + { + "ename": "KeyError", + "evalue": "'neighbourhood'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mcity\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'city'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mcounty\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'county'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mnei\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'components'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'neighbourhood'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0mlocalidad\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcountry\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mcity\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mcounty\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m', '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mnei\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mfcoordinates\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcoordinates\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: 'neighbourhood'" + ] + } + ], + "source": [ + "x = input('Where would you like your office? ')\n", + "m = input('Whats the max distance you would like to evaluate: ')\n", + "results = geocoder.geocode(x)\n", + "fcoordinates=[]\n", + "coordinates=[]\n", + "coordinates.append(results[0]['geometry']['lng'])\n", + "coordinates.append(results[0]['geometry']['lat']) \n", + "bandera = results[0]['annotations']['flag']\n", + "country = results[0]['components']['country']\n", + "city=results[0]['components']['city']\n", + "county = results[0]['components']['county']\n", + "nei = results[0]['components']['neighbourhood']\n", + "localidad = country+', '+city+', '+county+', '+nei\n", + "fcoordinates.append(coordinates)\n", + "fcoordinates.append(m)\n", + "fcoordinates.append(localidad)\n", + "fcoordinates.append(x)\n", + "fcoordinates.append(bandera)\n", + "fcoordinates" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [], + "source": [ + "import pickle" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [], + "source": [ + "with open('rest_data_ca.pkl', 'rb') as f:\n", + " data = pickle.load(f)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame(data)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " Cuisine\n", + " address\n", + " name\n", + " postalCode\n", + " Tag\n", + " ratings\n", + " \n", + " \n", + " \n", + " \n", + " 0\n", + " Fast Food\n", + " 925 Blossom Hill Road Oakridge Mall\n", + " Buca Di Beppo - San Jose - Oakridge\n", + " 95123\n", + " Food\n", + " 4\n", + " \n", + " \n", + " 1\n", + " Fast Food\n", + " 26900 Newport Rd\n", + " Giovanni's Pizza and Pasta\n", + " 92584\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 2\n", + " Fast Food\n", + " 3060 Naglee Rd\n", + " Applebee's Tracy\n", + " 95304\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 3\n", + " Fast Food\n", + " 50a\n", + " Patrick Molloy's Sports Pub\n", + " 90254\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 4\n", + " Fast Food\n", + " 555 Soquel Ave\n", + " Ristorante Italiano\n", + " 95062\n", + " Food\n", + " 4\n", + " \n", + " \n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " \n", + " \n", + " 56153\n", + " All\n", + " 3470 E 1ST ST\n", + " LA BUFADORA BAR\n", + " 90063\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 56154\n", + " All\n", + " 10250 SANTA MONICA BLVD # 1025\n", + " SAINT MARC\n", + " 90067\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 56155\n", + " All\n", + " 217 W TEMPLE AVE\n", + " HALL OF JUSTICE\n", + " 90012\n", + " Food\n", + " 4\n", + " \n", + " \n", + " 56156\n", + " All\n", + " 5750 MELROSE AVE\n", + " FIN-MELROSE\n", + " 90038\n", + " Food\n", + " 3\n", + " \n", + " \n", + " 56157\n", + " All\n", + " 6741 HOLLYWOOD BLVD\n", + " JUICY WINGZ\n", + " 90028\n", + " Food\n", + " 4\n", + " \n", + " \n", + "\n", + "52477 rows × 6 columns\n", + "" + ], + "text/plain": [ + " Cuisine address \\\n", + "0 Fast Food 925 Blossom Hill Road Oakridge Mall \n", + "1 Fast Food 26900 Newport Rd \n", + "2 Fast Food 3060 Naglee Rd \n", + "3 Fast Food 50a \n", + "4 Fast Food 555 Soquel Ave \n", + "... ... ... \n", + "56153 All 3470 E 1ST ST \n", + "56154 All 10250 SANTA MONICA BLVD # 1025 \n", + "56155 All 217 W TEMPLE AVE \n", + "56156 All 5750 MELROSE AVE \n", + "56157 All 6741 HOLLYWOOD BLVD \n", + "\n", + " name postalCode Tag ratings \n", + "0 Buca Di Beppo - San Jose - Oakridge 95123 Food 4 \n", + "1 Giovanni's Pizza and Pasta 92584 Food 3 \n", + "2 Applebee's Tracy 95304 Food 3 \n", + "3 Patrick Molloy's Sports Pub 90254 Food 3 \n", + "4 Ristorante Italiano 95062 Food 4 \n", + "... ... ... ... ... \n", + "56153 LA BUFADORA BAR 90063 Food 3 \n", + "56154 SAINT MARC 90067 Food 3 \n", + "56155 HALL OF JUSTICE 90012 Food 4 \n", + "56156 FIN-MELROSE 90038 Food 3 \n", + "56157 JUICY WINGZ 90028 Food 4 \n", + "\n", + "[52477 rows x 6 columns]" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.8.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/module-2/python-bi-project/python-bi-project - Esteban/rest_data_ca.pkl b/module-2/python-bi-project/python-bi-project - Esteban/rest_data_ca.pkl new file mode 100755 index 0000000..1c1cdeb Binary files /dev/null and b/module-2/python-bi-project/python-bi-project - Esteban/rest_data_ca.pkl differ
3711 rows × 14 columns
52477 rows × 6 columns