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": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idnamepermalinkcrunchbase_urlhomepage_urlblog_urlblog_feed_urltwitter_usernamecategory_codenumber_of_employees...officesmilestonesvideo_embedsscreenshotsexternal_linkspartnersdeadpooled_monthdeadpooled_daydeadpooled_urlipo
052cdef7c4bab8bd675297d8aWetpaintabc2http://www.crunchbase.com/company/wetpainthttp://wetpaint-inc.comhttp://digitalquarters.net/http://digitalquarters.net/feed/BachelrWetpaintweb47.0...[{'description': '', 'address1': '710 - 2nd Av...[{'id': 5869, 'description': 'Wetpaint named i...[][{'available_sizes': [[[150, 86], 'assets/imag...[{'external_url': 'http://www.geekwire.com/201...[]NaNNaNNaNNaN
152cdef7c4bab8bd675297d8bAdventNetabc3http://www.crunchbase.com/company/adventnethttp://adventnet.commanageengineenterprise600.0...[{'description': 'Headquarters', 'address1': '...[][][{'available_sizes': [[[150, 94], 'assets/imag...[][]NaNNaNNaNNaN
252cdef7c4bab8bd675297d8cZohoabc4http://www.crunchbase.com/company/zohohttp://zoho.comhttp://blogs.zoho.com/http://blogs.zoho.com/feedzohosoftware1600.0...[{'description': 'Headquarters', 'address1': '...[{'id': 388, 'description': 'Zoho Reaches 2 Mi...[{'embed_code': '<object width=\"430\" height=\"2...[][{'external_url': 'http://www.online-tech-tips...[]NaNNaNNaNNaN
352cdef7c4bab8bd675297d8dDiggdigghttp://www.crunchbase.com/company/digghttp://www.digg.comhttp://blog.digg.com/http://blog.digg.com/?feed=rss2diggnews60.0...[{'description': None, 'address1': '135 Missis...[{'id': 9588, 'description': 'Another Digg Exe...[{'embed_code': '<embed src=\"http://blip.tv/pl...[{'available_sizes': [[[117, 150], 'assets/ima...[{'external_url': 'http://www.sociableblog.com...[]NaNNaNNoneNone
452cdef7c4bab8bd675297d8eFacebookfacebookhttp://www.crunchbase.com/company/facebookhttp://facebook.comhttp://blog.facebook.comhttp://blog.facebook.com/atom.phpfacebooksocial5299.0...[{'description': 'Headquarters', 'address1': '...[{'id': 108, 'description': 'Facebook adds com...[][{'available_sizes': [[[150, 68], 'assets/imag...[{'external_url': 'http://latimesblogs.latimes...[]NaNNaN{'valuation_amount': 104000000000, 'valuation_...
\n", + "

5 rows × 42 columns

\n", + "
" + ], + "text/plain": [ + " _id name permalink \\\n", + "0 52cdef7c4bab8bd675297d8a Wetpaint abc2 \n", + "1 52cdef7c4bab8bd675297d8b AdventNet abc3 \n", + "2 52cdef7c4bab8bd675297d8c Zoho abc4 \n", + "3 52cdef7c4bab8bd675297d8d Digg digg \n", + "4 52cdef7c4bab8bd675297d8e Facebook facebook \n", + "\n", + " crunchbase_url homepage_url \\\n", + "0 http://www.crunchbase.com/company/wetpaint http://wetpaint-inc.com \n", + "1 http://www.crunchbase.com/company/adventnet http://adventnet.com \n", + "2 http://www.crunchbase.com/company/zoho http://zoho.com \n", + "3 http://www.crunchbase.com/company/digg http://www.digg.com \n", + "4 http://www.crunchbase.com/company/facebook http://facebook.com \n", + "\n", + " blog_url blog_feed_url \\\n", + "0 http://digitalquarters.net/ http://digitalquarters.net/feed/ \n", + "1 \n", + "2 http://blogs.zoho.com/ http://blogs.zoho.com/feed \n", + "3 http://blog.digg.com/ http://blog.digg.com/?feed=rss2 \n", + "4 http://blog.facebook.com http://blog.facebook.com/atom.php \n", + "\n", + " twitter_username category_code number_of_employees ... \\\n", + "0 BachelrWetpaint web 47.0 ... \n", + "1 manageengine 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': '... \n", + "\n", + " milestones \\\n", + "0 [{'id': 5869, 'description': 'Wetpaint named i... \n", + "1 [] \n", + "2 [{'id': 388, 'description': 'Zoho Reaches 2 Mi... \n", + "3 [{'id': 9588, 'description': 'Another Digg Exe... \n", + "4 [{'id': 108, 'description': 'Facebook adds com... \n", + "\n", + " video_embeds \\\n", + "0 [] \n", + "1 [] \n", + "2 [{'embed_code': '\n", + "RangeIndex: 18801 entries, 0 to 18800\n", + "Data columns (total 42 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 _id 18801 non-null object \n", + " 1 name 18801 non-null object \n", + " 2 permalink 18801 non-null object \n", + " 3 crunchbase_url 18801 non-null object \n", + " 4 homepage_url 16895 non-null object \n", + " 5 blog_url 16890 non-null object \n", + " 6 blog_feed_url 16757 non-null object \n", + " 7 twitter_username 11383 non-null object \n", + " 8 category_code 16050 non-null object \n", + " 9 number_of_employees 8889 non-null float64\n", + " 10 founded_year 13136 non-null float64\n", + " 11 founded_month 7898 non-null float64\n", + " 12 founded_day 5569 non-null float64\n", + " 13 deadpooled_year 929 non-null float64\n", + " 14 tag_list 14748 non-null object \n", + " 15 alias_list 8932 non-null object \n", + " 16 email_address 16793 non-null object \n", + " 17 phone_number 16778 non-null object \n", + " 18 description 12360 non-null object \n", + " 19 created_at 18801 non-null object \n", + " 20 updated_at 18801 non-null object \n", + " 21 overview 16820 non-null object \n", + " 22 image 16175 non-null object \n", + " 23 products 18801 non-null object \n", + " 24 relationships 18801 non-null object \n", + " 25 competitions 18801 non-null object \n", + " 26 providerships 18801 non-null object \n", + " 27 total_money_raised 18801 non-null object \n", + " 28 funding_rounds 18801 non-null object \n", + " 29 investments 18801 non-null object \n", + " 30 acquisition 2677 non-null object \n", + " 31 acquisitions 18801 non-null object \n", + " 32 offices 18801 non-null object \n", + " 33 milestones 18801 non-null object \n", + " 34 video_embeds 18801 non-null object \n", + " 35 screenshots 18801 non-null object \n", + " 36 external_links 18801 non-null object \n", + " 37 partners 18801 non-null object \n", + " 38 deadpooled_month 765 non-null float64\n", + " 39 deadpooled_day 648 non-null float64\n", + " 40 deadpooled_url 1079 non-null object \n", + " 41 ipo 390 non-null object \n", + "dtypes: float64(7), object(35)\n", + "memory usage: 6.0+ MB\n" + ] + } + ], + "source": [ + "data.info()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 1\n", + "#### Define client type: as I mentioned in the README ,they want to be sorrounded with Small and Medium Business, they want to have a coffee shop nearby and they want to be in San Diego California" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 2. \n", + "#### Correctly query the data I want. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namecategory_codenumber_of_employeesfounded_yeardeadpooled_yeartotal_money_raisedoffices
0Diggnews60.02004.0None$45M[{'description': None, 'address1': '135 Missis...
1Facebooksocial5299.02004.0None$2.43B[{'description': 'Headquarters', 'address1': '...
2PostiniwebNaN1999.0None$0[{'description': None, 'address1': '959 Skyway...
3Geniweb18.02006.0None$16.5M[{'description': 'Headquarters', 'address1': '...
4Flektorgames_videoNaNNaNNone$0[{'description': None, 'address1': '8536 Natio...
\n", + "
" + ], + "text/plain": [ + " name category_code number_of_employees founded_year deadpooled_year \\\n", + "0 Digg news 60.0 2004.0 None \n", + "1 Facebook social 5299.0 2004.0 None \n", + "2 Postini web NaN 1999.0 None \n", + "3 Geni web 18.0 2006.0 None \n", + "4 Flektor games_video NaN NaN None \n", + "\n", + " total_money_raised offices \n", + "0 $45M [{'description': None, 'address1': '135 Missis... \n", + "1 $2.43B [{'description': 'Headquarters', 'address1': '... \n", + "2 $0 [{'description': None, 'address1': '959 Skyway... \n", + "3 $16.5M [{'description': 'Headquarters', 'address1': '... \n", + "4 $0 [{'description': None, 'address1': '8536 Natio... " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Selecting only the ones that have offices and do not have deadpool year\n", + "cole = col.find({'offices': {'$not': {'$size':0}},\n", + " 'deadpooled_year':{'$type':'null'}},\n", + " {'_id':0 ,'name':1,'category_code':1,'number_of_employees':1,\n", + " 'offices':1,'founded_year':1,'deadpooled_year':1,'total_money_raised':1})\n", + "data = pd.DataFrame(cole)\n", + "data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 12957 entries, 0 to 12956\n", + "Data columns (total 7 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 name 12957 non-null object \n", + " 1 category_code 12310 non-null object \n", + " 2 number_of_employees 7039 non-null float64\n", + " 3 founded_year 10630 non-null float64\n", + " 4 deadpooled_year 0 non-null object \n", + " 5 total_money_raised 12957 non-null object \n", + " 6 offices 12957 non-null object \n", + "dtypes: float64(2), object(5)\n", + "memory usage: 708.7+ KB\n" + ] + } + ], + "source": [ + "data.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(12957, 7)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 3\n", + "#### Transforming data according to client needs" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 12957/12957 [02:05<00:00, 102.86it/s]\n" + ] + } + ], + "source": [ + "#Generate a list with dataframes with office information.\n", + "#adding a column with name, total employees, category and number of offices\n", + "\n", + "lista_df=[] \n", + "\n", + "for i in tqdm(range(len(data.offices))):\n", + " df = pd.DataFrame(data.iloc[i].offices)\n", + " df['name'] = str(data.loc[i,['name'][0]])\n", + " df['total_employees'] = data.iloc[i].number_of_employees\n", + " df['category'] = str(data.loc[i,['category_code'][0]])\n", + " df['total_offices'] = len(data.iloc[i].offices)\n", + " lista_df.append(df)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12957" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(lista_df)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_employeescategorytotal_offices
0None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395Digg60.0news1
1Headquarters1601 Willow Road94025Menlo ParkCAUSA37.416-122.152Facebook5299.0social3
2Europe HQDublinNoneIRL53.3441-6.26749Facebook5299.0social3
3New York340 Madison Ave10017New YorkNYUSA40.7557-73.9792Facebook5299.0social3
4None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248PostiniNaNweb1
\n", + "
" + ], + "text/plain": [ + " description address1 address2 zip_code city \\\n", + "0 None 135 Mississippi St 94107 San Francisco \n", + "1 Headquarters 1601 Willow Road 94025 Menlo Park \n", + "2 Europe HQ Dublin \n", + "3 New York 340 Madison Ave 10017 New York \n", + "4 None 959 Skyway Road, Suite 200 None 94070 San Carlos \n", + "\n", + " state_code country_code latitude longitude name total_employees \\\n", + "0 CA USA 37.7647 -122.395 Digg 60.0 \n", + "1 CA USA 37.416 -122.152 Facebook 5299.0 \n", + "2 None IRL 53.3441 -6.26749 Facebook 5299.0 \n", + "3 NY USA 40.7557 -73.9792 Facebook 5299.0 \n", + "4 CA USA 37.5069 -122.248 Postini NaN \n", + "\n", + " category total_offices \n", + "0 news 1 \n", + "1 social 3 \n", + "2 social 3 \n", + "3 social 3 \n", + "4 web 1 " + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final = pd.concat(lista_df).reset_index(drop=True)\n", + "final.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15848, 13)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "country_code\n", + "USA 9652\n", + "GBR 1327\n", + "CAN 591\n", + "IND 509\n", + "DEU 392\n", + "FRA 359\n", + "AUS 263\n", + "ESP 232\n", + "ISR 213\n", + "CHN 196\n", + "Name: name, dtype: int64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.groupby('country_code')['name'].count().sort_values(ascending=False).head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 15848/15848 [00:01<00:00, 8747.27it/s]\n" + ] + } + ], + "source": [ + "#genero una lista con los geopuntos en formato de diccionario\n", + "lista_points = []\n", + "for i in tqdm(range(len(final.longitude))):\n", + " \n", + " lista_points.append(dict({'type':'Point',\n", + " 'coordinates': [final.longitude[i],\n", + " final.latitude[i]]}))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15848" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(lista_points)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "#agrego los puntos al DataFrame \n", + "final['principal'] = pd.Series(lista_points)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['description', 'address1', 'address2', 'zip_code', 'city', 'state_code',\n", + " 'country_code', 'latitude', 'longitude', 'name', 'total_employees',\n", + " 'category', 'total_offices', 'principal'],\n", + " dtype='object')" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15848, 14)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "#reordeno el dataframe\n", + "final = final[['name','total_employees','category','total_offices','description','address1',\n", + " 'address2','zip_code','city','state_code','country_code','latitude','longitude','principal']]" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nametotal_employeescategorytotal_officesdescriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudeprincipalcompany_size
0Digg60.0news1None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395{'type': 'Point', 'coordinates': [-122.394523,...SMB
1Facebook5299.0social3Headquarters1601 Willow Road94025Menlo ParkCAUSA37.416-122.152{'type': 'Point', 'coordinates': [-122.151801,...JUMBO
2Facebook5299.0social3Europe HQDublinNoneIRL53.3441-6.26749{'type': 'Point', 'coordinates': [-6.267494, 5...JUMBO
3Facebook5299.0social3New York340 Madison Ave10017New YorkNYUSA40.7557-73.9792{'type': 'Point', 'coordinates': [-73.9792469,...JUMBO
4PostiniNaNweb1None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248{'type': 'Point', 'coordinates': [-122.247573,...SMB
\n", + "
" + ], + "text/plain": [ + " name total_employees category total_offices description \\\n", + "0 Digg 60.0 news 1 None \n", + "1 Facebook 5299.0 social 3 Headquarters \n", + "2 Facebook 5299.0 social 3 Europe HQ \n", + "3 Facebook 5299.0 social 3 New York \n", + "4 Postini NaN web 1 None \n", + "\n", + " address1 address2 zip_code city state_code \\\n", + "0 135 Mississippi St 94107 San Francisco CA \n", + "1 1601 Willow Road 94025 Menlo Park CA \n", + "2 Dublin None \n", + "3 340 Madison Ave 10017 New York NY \n", + "4 959 Skyway Road, Suite 200 None 94070 San Carlos CA \n", + "\n", + " country_code latitude longitude \\\n", + "0 USA 37.7647 -122.395 \n", + "1 USA 37.416 -122.152 \n", + "2 IRL 53.3441 -6.26749 \n", + "3 USA 40.7557 -73.9792 \n", + "4 USA 37.5069 -122.248 \n", + "\n", + " principal company_size \n", + "0 {'type': 'Point', 'coordinates': [-122.394523,... SMB \n", + "1 {'type': 'Point', 'coordinates': [-122.151801,... JUMBO \n", + "2 {'type': 'Point', 'coordinates': [-6.267494, 5... JUMBO \n", + "3 {'type': 'Point', 'coordinates': [-73.9792469,... JUMBO \n", + "4 {'type': 'Point', 'coordinates': [-122.247573,... SMB " + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#agrego columna JUMBO o SMB dependiendo de la cantidad de empleados\n", + "final['company_size'] = np.where(final.total_employees>1000,'JUMBO','SMB')\n", + "\n", + "final.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nametotal_employeescategorytotal_officesdescriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudeprincipalcompany_size
0Digg60.0news1None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395{'type': 'Point', 'coordinates': [-122.394523,...SMB
4PostiniNaNweb1None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248{'type': 'Point', 'coordinates': [-122.247573,...SMB
5Geni18.0web1Headquarters9229 W. Sunset Blvd.90069West HollywoodCAUSA34.0904-118.393{'type': 'Point', 'coordinates': [-118.393064,...SMB
6FlektorNaNgames_video1None8536 National Blvd, Suite ANone90232Culver CityCAUSA34.026-118.38{'type': 'Point', 'coordinates': [-118.379768,...SMB
7Fox Interactive Media0.0web1407 N Maple Dr90210Beverly HillsCAUSA34.0762-118.394{'type': 'Point', 'coordinates': [-118.39417, ...SMB
\n", + "
" + ], + "text/plain": [ + " name total_employees category total_offices \\\n", + "0 Digg 60.0 news 1 \n", + "4 Postini NaN web 1 \n", + "5 Geni 18.0 web 1 \n", + "6 Flektor NaN games_video 1 \n", + "7 Fox Interactive Media 0.0 web 1 \n", + "\n", + " description address1 address2 zip_code \\\n", + "0 None 135 Mississippi St 94107 \n", + "4 None 959 Skyway Road, Suite 200 None 94070 \n", + "5 Headquarters 9229 W. Sunset Blvd. 90069 \n", + "6 None 8536 National Blvd, Suite A None 90232 \n", + "7 407 N Maple Dr 90210 \n", + "\n", + " city state_code country_code latitude longitude \\\n", + "0 San Francisco CA USA 37.7647 -122.395 \n", + "4 San Carlos CA USA 37.5069 -122.248 \n", + "5 West Hollywood CA USA 34.0904 -118.393 \n", + "6 Culver City CA USA 34.026 -118.38 \n", + "7 Beverly Hills CA USA 34.0762 -118.394 \n", + "\n", + " principal company_size \n", + "0 {'type': 'Point', 'coordinates': [-122.394523,... SMB \n", + "4 {'type': 'Point', 'coordinates': [-122.247573,... SMB \n", + "5 {'type': 'Point', 'coordinates': [-118.393064,... SMB \n", + "6 {'type': 'Point', 'coordinates': [-118.379768,... SMB \n", + "7 {'type': 'Point', 'coordinates': [-118.39417, ... SMB " + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#elimino a las empresas JUMBO\n", + "final = final[final.company_size == 'SMB']\n", + "final.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15383, 15)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "final.dropna(subset=['latitude','longitude'],inplace=True) " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(9919, 15)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 4\n", + "#### Create a new collection with the final DataFrame in MongoCompass so we can add a 2dsphere index. " + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#inserto en compass el data frame resultante en una nueva coleccion\n", + "db.project.insert_many(final.to_dict('records')) " + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'principal_2dsphere'" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#creo el índice 2dsphere para poder hacer geoqueries\n", + "db.project.create_index([('principal', '2dsphere')])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 5\n", + "\n", + "#### Make geoqueries of the new collection with client conditions" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "cole = db.project" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "#funcion que me permite encontrar puntos cercanos con radio por default de 1000 metros\n", + "def find_near(geopoint, radio=10000):\n", + " \n", + " return cole.find({'principal':{\n", + " '$near': {'$geometry': geopoint, '$maxDistance':radio}\n", + " }})" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "#inicializo la conexión con geocoder\n", + "key = 'd8314354b31d46a298e0f21ffb920a34'\n", + "geocoder = OpenCageGeocode(key)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "#función que permite al usuario elegir una dirección y en base a la misma devuelve los datos necesarios para hacer la geoquery\n", + "def getting_coor():\n", + " try:\n", + " 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", + " localidad = country+', '+city\n", + " fcoordinates.append(coordinates)\n", + " fcoordinates.append(m)\n", + " fcoordinates.append(localidad)\n", + " fcoordinates.append(x)\n", + " fcoordinates.append(bandera)\n", + " return fcoordinates\n", + " except:\n", + " return 'Not a valid address'" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? San Diego California\n", + "Whats the max distance you would like to evaluate: 2500\n", + "Amount of offices near San Diego California are: 24\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#este podría ser el código principal que solicita el input del usuario y devuelve el mapa\n", + "\n", + "coordenadas = getting_coor() #acá inicializa la funcion creada arriba\n", + "longlat = coordenadas[0]\n", + "latlong = longlat[::-1]\n", + "radio = int(coordenadas[1])\n", + "pais = coordenadas[4]\n", + "localidad = coordenadas[2]\n", + "direccion_solicitud = coordenadas[3]\n", + "\n", + "address={'type': 'Point', 'coordinates':longlat} # geopoint\n", + "\n", + "ratio=radio # radio de busqueda\n", + "\n", + "n_ofi=find_near(address, ratio).count()\n", + "ofi = find_near(address, ratio)\n", + "ofi=pd.DataFrame(ofi)\n", + "\n", + "#creating map object\n", + "tooltip = 'Location you chose: {} \\n {}'.format(direccion_solicitud,localidad)\n", + "mapa=folium.Map(latlong, zoom_start=12, width='100%', height='100%')\n", + "datamapa=ofi[['latitude', 'longitude']].values\n", + "mapa.add_child(plugins.HeatMap(datamapa, radius=15))\n", + "folium.Marker(latlong, tooltip=tooltip, icon=folium.Icon()).add_to(mapa)\n", + "mapa.save('MapaFinal.html')\n", + "print('Amount of offices near {} are: {}'.format(direccion_solicitud,n_ofi))\n", + "mapa\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 6\n", + "#### Get more information about restaurants in the area and display them with the heatmap mentioned above and marking where the restaurants of coffee shops are. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Found a DB in Kaggle with California restaurants. I proceed to explore and clean data" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "#https://www.kaggle.com/vaibhavsxn/restaurants-in-california\n", + "\n", + "with open('rest_data_ca.pkl', 'rb') as rest:\n", + " data = pickle.load(rest)\n", + " \n", + "dfrest = pd.DataFrame(data)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Int64Index: 52477 entries, 0 to 56157\n", + "Data columns (total 6 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Cuisine 52477 non-null object\n", + " 1 address 52477 non-null object\n", + " 2 name 52477 non-null object\n", + " 3 postalCode 52477 non-null object\n", + " 4 Tag 52477 non-null object\n", + " 5 ratings 52477 non-null int64 \n", + "dtypes: int64(1), object(5)\n", + "memory usage: 2.8+ MB\n" + ] + } + ], + "source": [ + "dfrest.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "All 47851\n", + "Mexican 4530\n", + "Fast Food 64\n", + "Veg 32\n", + "Name: Cuisine, dtype: int64" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.Cuisine.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Food 52477\n", + "Name: Tag, dtype: int64" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.Tag.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4 26428\n", + "3 26049\n", + "Name: ratings, dtype: int64" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.ratings.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratings
0Fast Food925 Blossom Hill Road Oakridge MallBuca Di Beppo - San Jose - Oakridge95123Food4
1Fast Food555 Soquel AveRistorante Italiano95062Food4
2Fast Food9822 Libra AveMilanos Pizza95827Food4
3Fast Food1640 Camino Del Rio NTilted Kilt Mission Valley92108Food4
4Fast Food1231 Park StThe Fire Den94501Food4
.....................
26423All6719 LA TIJERA BLVD # A-BCHIPOTLE #309490045Food4
26424All100 1/2 7TH STBRAAZO PIZZA90014Food4
26425All1244 WESTWOOD BLVDPOKE'ME90024Food4
26426All217 W TEMPLE AVEHALL OF JUSTICE90012Food4
26427All6741 HOLLYWOOD BLVDJUICY WINGZ90028Food4
\n", + "

26428 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " Cuisine address \\\n", + "0 Fast Food 925 Blossom Hill Road Oakridge Mall \n", + "1 Fast Food 555 Soquel Ave \n", + "2 Fast Food 9822 Libra Ave \n", + "3 Fast Food 1640 Camino Del Rio N \n", + "4 Fast Food 1231 Park St \n", + "... ... ... \n", + "26423 All 6719 LA TIJERA BLVD # A-B \n", + "26424 All 100 1/2 7TH ST \n", + "26425 All 1244 WESTWOOD BLVD \n", + "26426 All 217 W TEMPLE AVE \n", + "26427 All 6741 HOLLYWOOD BLVD \n", + "\n", + " name postalCode Tag ratings \n", + "0 Buca Di Beppo - San Jose - Oakridge 95123 Food 4 \n", + "1 Ristorante Italiano 95062 Food 4 \n", + "2 Milanos Pizza 95827 Food 4 \n", + "3 Tilted Kilt Mission Valley 92108 Food 4 \n", + "4 The Fire Den 94501 Food 4 \n", + "... ... ... ... ... \n", + "26423 CHIPOTLE #3094 90045 Food 4 \n", + "26424 BRAAZO PIZZA 90014 Food 4 \n", + "26425 POKE'ME 90024 Food 4 \n", + "26426 HALL OF JUSTICE 90012 Food 4 \n", + "26427 JUICY WINGZ 90028 Food 4 \n", + "\n", + "[26428 rows x 6 columns]" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#removing restaurants with low ratings\n", + "dfrest = dfrest[dfrest.ratings>=4]\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "# Using REGEX so I can categorize the restaurant type\n", + "\n", + "def typerest(x):\n", + " if re.search(r'pizza',x.lower()) or re.search(r'pasta',x.lower()) or re.search(r'italia',x.lower()):\n", + " x='Italian'\n", + " elif re.search(r'burger',x.lower()):\n", + " x='Burger'\n", + " elif re.search(r'coffee',x.lower()):\n", + " x='CoffeeShop'\n", + " elif re.search(r'coffee',x.lower()):\n", + " x='CoffeeShop'\n", + " elif re.search(r'pie',x.lower()) or re.search(r'cake',x.lower()) or re.search(r'dess?ert',x.lower()):\n", + " x='Dessert'\n", + " elif re.search(r'mex',x.lower()) or re.search(r'taco',x.lower()):\n", + " x='Mexican'\n", + " elif re.search(r'sushi',x.lower()) or re.search(r'poke',x.lower()) or re.search(r'dumpling',x.lower())\\\n", + " or re.search(r'asia',x.lower()) or re.search(r'china?e?',x.lower()) or re.search(r'japan',x.lower())\\\n", + " or re.search(r'korea',x.lower()):\n", + " x='Asian'\n", + " else:\n", + " x='other'\n", + " \n", + " return x " + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 26428/26428 [00:00<00:00, 27249.91it/s]\n" + ] + } + ], + "source": [ + "#applying the above function to the data frame using TQDM\n", + "tqdm.pandas()\n", + "dfrest['type'] = dfrest['name'].progress_apply(typerest)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0Fast Food925 Blossom Hill Road Oakridge MallBuca Di Beppo - San Jose - Oakridge95123Food4other
1Fast Food555 Soquel AveRistorante Italiano95062Food4Italian
2Fast Food9822 Libra AveMilanos Pizza95827Food4Italian
3Fast Food1640 Camino Del Rio NTilted Kilt Mission Valley92108Food4other
4Fast Food1231 Park StThe Fire Den94501Food4other
\n", + "
" + ], + "text/plain": [ + " Cuisine address \\\n", + "0 Fast Food 925 Blossom Hill Road Oakridge Mall \n", + "1 Fast Food 555 Soquel Ave \n", + "2 Fast Food 9822 Libra Ave \n", + "3 Fast Food 1640 Camino Del Rio N \n", + "4 Fast Food 1231 Park St \n", + "\n", + " name postalCode Tag ratings type \n", + "0 Buca Di Beppo - San Jose - Oakridge 95123 Food 4 other \n", + "1 Ristorante Italiano 95062 Food 4 Italian \n", + "2 Milanos Pizza 95827 Food 4 Italian \n", + "3 Tilted Kilt Mission Valley 92108 Food 4 other \n", + "4 The Fire Den 94501 Food 4 other " + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "other 22147\n", + "Mexican 1165\n", + "Asian 929\n", + "Italian 833\n", + "CoffeeShop 632\n", + "Burger 552\n", + "Dessert 170\n", + "Name: type, dtype: int64" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.type.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0Fast Food555 Soquel AveRistorante Italiano95062Food4Italian
1Fast Food9822 Libra AveMilanos Pizza95827Food4Italian
2Fast Food5365 Alton PkwyZpizza92604Food4Italian
3Fast Food6593 Collins DrCustom Pie93021Food4Dessert
4Fast Food820 N Alta AveYou-be's U-bake Pizza93618Food4Italian
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode Tag \\\n", + "0 Fast Food 555 Soquel Ave Ristorante Italiano 95062 Food \n", + "1 Fast Food 9822 Libra Ave Milanos Pizza 95827 Food \n", + "2 Fast Food 5365 Alton Pkwy Zpizza 92604 Food \n", + "3 Fast Food 6593 Collins Dr Custom Pie 93021 Food \n", + "4 Fast Food 820 N Alta Ave You-be's U-bake Pizza 93618 Food \n", + "\n", + " ratings type \n", + "0 4 Italian \n", + "1 4 Italian \n", + "2 4 Italian \n", + "3 4 Dessert \n", + "4 4 Italian " + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Because of the request number restriction, \n", + "#Im deleting every \"other\" type restaurant in database\n", + "dfrest = dfrest[dfrest.type != 'other']\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type \n", + "0 Food 4 Mexican \n", + "1 Food 4 Burger \n", + "2 Food 4 Burger \n", + "3 Food 4 Mexican \n", + "4 Food 4 Burger " + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#getting a sample of 2000 restaurantes because of api restriction\n", + "dfrest = dfrest.sample(2000)\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2000, 7)" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "#function to obtain latitude and longitude of the addresses in DF\n", + "def gettingres_coor(x):\n", + " try:\n", + " results = geocoder.geocode(x)\n", + " coordinates=[]\n", + " coordinates.append(results[0]['geometry']['lng'])\n", + " coordinates.append(results[0]['geometry']['lat']) \n", + " return coordinates\n", + " except:\n", + " return np.nan" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 2000/2000 [39:35<00:00, 1.19s/it] \n" + ] + } + ], + "source": [ + "#applying function to DF\n", + "tqdm.pandas()\n", + "dfrest['coordinates'] = dfrest.address.progress_apply(gettingres_coor)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "#removing nan values\n", + "dfrest.dropna(inplace=True)\n", + "dfrest.reset_index(drop = True, inplace = True)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "#splitting columns\n", + "dfrest['latitude'] = dfrest.coordinates.apply(lambda x:x[1])\n", + "dfrest['longitude'] = dfrest.coordinates.apply(lambda x:x[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitude
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican[-117.7520488, 34.0684236]34.068424-117.752049
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger[-118.3018267, 34.1799755]34.179975-118.301827
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger[-118.0734294, 34.0840807]34.084081-118.073429
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican[-118.5031071, 34.2285216]34.228522-118.503107
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger[-75.926111, 42.105103]42.105103-75.926111
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type coordinates latitude longitude \n", + "0 Food 4 Mexican [-117.7520488, 34.0684236] 34.068424 -117.752049 \n", + "1 Food 4 Burger [-118.3018267, 34.1799755] 34.179975 -118.301827 \n", + "2 Food 4 Burger [-118.0734294, 34.0840807] 34.084081 -118.073429 \n", + "3 Food 4 Mexican [-118.5031071, 34.2285216] 34.228522 -118.503107 \n", + "4 Food 4 Burger [-75.926111, 42.105103] 42.105103 -75.926111 " + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 1995/1995 [00:00<00:00, 4321.81it/s]\n" + ] + } + ], + "source": [ + "#getting a list of the geopoints\n", + "lista_pointsres = []\n", + "for i in tqdm(range(len(dfrest.latitude))):\n", + " lista_pointsres.append(dict({'type':'Point',\n", + " 'coordinates': [dfrest.longitude[i],\n", + " dfrest.latitude[i]]}))" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "#adding geopoints to main DF\n", + "dfrest['principal'] = pd.Series(lista_pointsres)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitudeprincipal
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican[-117.7520488, 34.0684236]34.068424-117.752049{'type': 'Point', 'coordinates': [-117.7520488...
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger[-118.3018267, 34.1799755]34.179975-118.301827{'type': 'Point', 'coordinates': [-118.3018267...
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger[-118.0734294, 34.0840807]34.084081-118.073429{'type': 'Point', 'coordinates': [-118.0734294...
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican[-118.5031071, 34.2285216]34.228522-118.503107{'type': 'Point', 'coordinates': [-118.5031071...
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger[-75.926111, 42.105103]42.105103-75.926111{'type': 'Point', 'coordinates': [-75.926111, ...
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type coordinates latitude longitude \\\n", + "0 Food 4 Mexican [-117.7520488, 34.0684236] 34.068424 -117.752049 \n", + "1 Food 4 Burger [-118.3018267, 34.1799755] 34.179975 -118.301827 \n", + "2 Food 4 Burger [-118.0734294, 34.0840807] 34.084081 -118.073429 \n", + "3 Food 4 Mexican [-118.5031071, 34.2285216] 34.228522 -118.503107 \n", + "4 Food 4 Burger [-75.926111, 42.105103] 42.105103 -75.926111 \n", + "\n", + " principal \n", + "0 {'type': 'Point', 'coordinates': [-117.7520488... \n", + "1 {'type': 'Point', 'coordinates': [-118.3018267... \n", + "2 {'type': 'Point', 'coordinates': [-118.0734294... \n", + "3 {'type': 'Point', 'coordinates': [-118.5031071... \n", + "4 {'type': 'Point', 'coordinates': [-75.926111, ... " + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#inserting to Compass\n", + "db.restaurantes.insert_many(dfrest.to_dict('records')) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'principal_2dsphere'" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#creating 2dsphere index\n", + "db.restaurantes.create_index([('principal', '2dsphere')])" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "#function to find restaurants near clients input\n", + "coleres = db.restaurantes\n", + "def find_near_res(geopoint, radio=10000):\n", + " \n", + " return coleres.find({'principal':{\n", + " '$near': {'$geometry': geopoint, '$maxDistance':radio}\n", + " }})" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? San Diego California\n", + "Whats the max distance you would like to evaluate: 2500\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 2/2 [00:00<00:00, 411.63it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Amount of offices near San Diego California are: 24\n", + "Amount of restaurants near San Diego California are: 2\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#main code to ask client where they want the office and getting all the needed information\n", + "\n", + "coordenadas = getting_coor() #function discribed above\n", + "longlat = coordenadas[0]\n", + "latlong = longlat[::-1]\n", + "radio = int(coordenadas[1])\n", + "pais = coordenadas[4]\n", + "localidad = coordenadas[2]\n", + "direccion_solicitud = coordenadas[3]\n", + "\n", + "address={'type': 'Point', 'coordinates':longlat} # geopoint\n", + "\n", + "ratio=radio # radio de busqueda\n", + "\n", + "#query for offices\n", + "n_ofi=find_near(address, ratio).count()\n", + "ofi = find_near(address, ratio)\n", + "ofi=pd.DataFrame(ofi)\n", + "\n", + "#query for restaurants\n", + "n_res=find_near_res(address, ratio).count()\n", + "restaurant = find_near_res(address, ratio)\n", + "restaurant = pd.DataFrame(restaurant)\n", + "\n", + "#creating map object\n", + "tooltip = 'Location you chose: {} \\n {}'.format(direccion_solicitud,localidad)\n", + "mapa=folium.Map(latlong, zoom_start=11)\n", + "datamapa=ofi[['latitude', 'longitude']].values\n", + "mapa.add_child(plugins.HeatMap(datamapa, radius=15))\n", + "folium.Marker(latlong, tooltip=tooltip, icon=folium.Icon(color='red')).add_to(mapa)\n", + "for i in trange(len(restaurant.latitude)):\n", + " folium.Marker([restaurant.latitude[i],restaurant.longitude[i]],\n", + " tooltip = restaurant.name[i], icon = folium.Icon()).add_to(mapa)\n", + "\n", + "mapa.save('MapaFinalRestaurantes.html')\n", + "print('Amount of offices near {} are: {}'.format(direccion_solicitud,n_ofi))\n", + "print('Amount of restaurants near {} are: {}'.format(direccion_solicitud,n_res))\n", + "mapa" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idCuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitudeprincipal
05e9db680e283983c43b35a8eAll740 W BROADWAYFRANK'S BURGER91204Food4Burger[-117.1701501, 32.7156373]32.715637-117.17015{'type': 'Point', 'coordinates': [-117.1701501...
15e9db680e283983c43b35e67All3995 24th StSTARBUCKS COFFEE #54594114Food4CoffeeShop[-117.14241, 32.706318]32.706318-117.14241{'type': 'Point', 'coordinates': [-117.14241, ...
\n", + "
" + ], + "text/plain": [ + " _id Cuisine address name \\\n", + "0 5e9db680e283983c43b35a8e All 740 W BROADWAY FRANK'S BURGER \n", + "1 5e9db680e283983c43b35e67 All 3995 24th St STARBUCKS COFFEE #545 \n", + "\n", + " postalCode Tag ratings type coordinates \\\n", + "0 91204 Food 4 Burger [-117.1701501, 32.7156373] \n", + "1 94114 Food 4 CoffeeShop [-117.14241, 32.706318] \n", + "\n", + " latitude longitude principal \n", + "0 32.715637 -117.17015 {'type': 'Point', 'coordinates': [-117.1701501... \n", + "1 32.706318 -117.14241 {'type': 'Point', 'coordinates': [-117.14241, ... " + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "restaurant.head()" + ] + }, + { + "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/.ipynb_checkpoints/draft-checkpoint.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/draft-checkpoint.ipynb new file mode 100644 index 0000000..7fec515 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/draft-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/geocoder testing-checkpoint.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/geocoder testing-checkpoint.ipynb new file mode 100644 index 0000000..7fec515 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/.ipynb_checkpoints/geocoder testing-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/module-2/python-bi-project/python-bi-project - Esteban/MapaFinal.html b/module-2/python-bi-project/python-bi-project - Esteban/MapaFinal.html new file mode 100644 index 0000000..99fce43 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/MapaFinal.html @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/module-2/python-bi-project/python-bi-project - Esteban/MapaFinalRestaurantes.html b/module-2/python-bi-project/python-bi-project - Esteban/MapaFinalRestaurantes.html new file mode 100644 index 0000000..75c1123 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/MapaFinalRestaurantes.html @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/module-2/python-bi-project/python-bi-project - Esteban/Project - Final.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/Project - Final.ipynb new file mode 100644 index 0000000..adca703 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/Project - Final.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": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idnamepermalinkcrunchbase_urlhomepage_urlblog_urlblog_feed_urltwitter_usernamecategory_codenumber_of_employees...officesmilestonesvideo_embedsscreenshotsexternal_linkspartnersdeadpooled_monthdeadpooled_daydeadpooled_urlipo
052cdef7c4bab8bd675297d8aWetpaintabc2http://www.crunchbase.com/company/wetpainthttp://wetpaint-inc.comhttp://digitalquarters.net/http://digitalquarters.net/feed/BachelrWetpaintweb47.0...[{'description': '', 'address1': '710 - 2nd Av...[{'id': 5869, 'description': 'Wetpaint named i...[][{'available_sizes': [[[150, 86], 'assets/imag...[{'external_url': 'http://www.geekwire.com/201...[]NaNNaNNaNNaN
152cdef7c4bab8bd675297d8bAdventNetabc3http://www.crunchbase.com/company/adventnethttp://adventnet.commanageengineenterprise600.0...[{'description': 'Headquarters', 'address1': '...[][][{'available_sizes': [[[150, 94], 'assets/imag...[][]NaNNaNNaNNaN
252cdef7c4bab8bd675297d8cZohoabc4http://www.crunchbase.com/company/zohohttp://zoho.comhttp://blogs.zoho.com/http://blogs.zoho.com/feedzohosoftware1600.0...[{'description': 'Headquarters', 'address1': '...[{'id': 388, 'description': 'Zoho Reaches 2 Mi...[{'embed_code': '<object width=\"430\" height=\"2...[][{'external_url': 'http://www.online-tech-tips...[]NaNNaNNaNNaN
352cdef7c4bab8bd675297d8dDiggdigghttp://www.crunchbase.com/company/digghttp://www.digg.comhttp://blog.digg.com/http://blog.digg.com/?feed=rss2diggnews60.0...[{'description': None, 'address1': '135 Missis...[{'id': 9588, 'description': 'Another Digg Exe...[{'embed_code': '<embed src=\"http://blip.tv/pl...[{'available_sizes': [[[117, 150], 'assets/ima...[{'external_url': 'http://www.sociableblog.com...[]NaNNaNNoneNone
452cdef7c4bab8bd675297d8eFacebookfacebookhttp://www.crunchbase.com/company/facebookhttp://facebook.comhttp://blog.facebook.comhttp://blog.facebook.com/atom.phpfacebooksocial5299.0...[{'description': 'Headquarters', 'address1': '...[{'id': 108, 'description': 'Facebook adds com...[][{'available_sizes': [[[150, 68], 'assets/imag...[{'external_url': 'http://latimesblogs.latimes...[]NaNNaN{'valuation_amount': 104000000000, 'valuation_...
\n", + "

5 rows × 42 columns

\n", + "
" + ], + "text/plain": [ + " _id name permalink \\\n", + "0 52cdef7c4bab8bd675297d8a Wetpaint abc2 \n", + "1 52cdef7c4bab8bd675297d8b AdventNet abc3 \n", + "2 52cdef7c4bab8bd675297d8c Zoho abc4 \n", + "3 52cdef7c4bab8bd675297d8d Digg digg \n", + "4 52cdef7c4bab8bd675297d8e Facebook facebook \n", + "\n", + " crunchbase_url homepage_url \\\n", + "0 http://www.crunchbase.com/company/wetpaint http://wetpaint-inc.com \n", + "1 http://www.crunchbase.com/company/adventnet http://adventnet.com \n", + "2 http://www.crunchbase.com/company/zoho http://zoho.com \n", + "3 http://www.crunchbase.com/company/digg http://www.digg.com \n", + "4 http://www.crunchbase.com/company/facebook http://facebook.com \n", + "\n", + " blog_url blog_feed_url \\\n", + "0 http://digitalquarters.net/ http://digitalquarters.net/feed/ \n", + "1 \n", + "2 http://blogs.zoho.com/ http://blogs.zoho.com/feed \n", + "3 http://blog.digg.com/ http://blog.digg.com/?feed=rss2 \n", + "4 http://blog.facebook.com http://blog.facebook.com/atom.php \n", + "\n", + " twitter_username category_code number_of_employees ... \\\n", + "0 BachelrWetpaint web 47.0 ... \n", + "1 manageengine 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': '... \n", + "\n", + " milestones \\\n", + "0 [{'id': 5869, 'description': 'Wetpaint named i... \n", + "1 [] \n", + "2 [{'id': 388, 'description': 'Zoho Reaches 2 Mi... \n", + "3 [{'id': 9588, 'description': 'Another Digg Exe... \n", + "4 [{'id': 108, 'description': 'Facebook adds com... \n", + "\n", + " video_embeds \\\n", + "0 [] \n", + "1 [] \n", + "2 [{'embed_code': '\n", + "RangeIndex: 18801 entries, 0 to 18800\n", + "Data columns (total 42 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 _id 18801 non-null object \n", + " 1 name 18801 non-null object \n", + " 2 permalink 18801 non-null object \n", + " 3 crunchbase_url 18801 non-null object \n", + " 4 homepage_url 16895 non-null object \n", + " 5 blog_url 16890 non-null object \n", + " 6 blog_feed_url 16757 non-null object \n", + " 7 twitter_username 11383 non-null object \n", + " 8 category_code 16050 non-null object \n", + " 9 number_of_employees 8889 non-null float64\n", + " 10 founded_year 13136 non-null float64\n", + " 11 founded_month 7898 non-null float64\n", + " 12 founded_day 5569 non-null float64\n", + " 13 deadpooled_year 929 non-null float64\n", + " 14 tag_list 14748 non-null object \n", + " 15 alias_list 8932 non-null object \n", + " 16 email_address 16793 non-null object \n", + " 17 phone_number 16778 non-null object \n", + " 18 description 12360 non-null object \n", + " 19 created_at 18801 non-null object \n", + " 20 updated_at 18801 non-null object \n", + " 21 overview 16820 non-null object \n", + " 22 image 16175 non-null object \n", + " 23 products 18801 non-null object \n", + " 24 relationships 18801 non-null object \n", + " 25 competitions 18801 non-null object \n", + " 26 providerships 18801 non-null object \n", + " 27 total_money_raised 18801 non-null object \n", + " 28 funding_rounds 18801 non-null object \n", + " 29 investments 18801 non-null object \n", + " 30 acquisition 2677 non-null object \n", + " 31 acquisitions 18801 non-null object \n", + " 32 offices 18801 non-null object \n", + " 33 milestones 18801 non-null object \n", + " 34 video_embeds 18801 non-null object \n", + " 35 screenshots 18801 non-null object \n", + " 36 external_links 18801 non-null object \n", + " 37 partners 18801 non-null object \n", + " 38 deadpooled_month 765 non-null float64\n", + " 39 deadpooled_day 648 non-null float64\n", + " 40 deadpooled_url 1079 non-null object \n", + " 41 ipo 390 non-null object \n", + "dtypes: float64(7), object(35)\n", + "memory usage: 6.0+ MB\n" + ] + } + ], + "source": [ + "data.info()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 1\n", + "#### Define client type: as I mentioned in the README ,they want to be sorrounded with Small and Medium Business, they want to have a coffee shop nearby and they want to be in San Diego California" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 2. \n", + "#### Correctly query the data I want. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namecategory_codenumber_of_employeesfounded_yeardeadpooled_yeartotal_money_raisedoffices
0Diggnews60.02004.0None$45M[{'description': None, 'address1': '135 Missis...
1Facebooksocial5299.02004.0None$2.43B[{'description': 'Headquarters', 'address1': '...
2PostiniwebNaN1999.0None$0[{'description': None, 'address1': '959 Skyway...
3Geniweb18.02006.0None$16.5M[{'description': 'Headquarters', 'address1': '...
4Flektorgames_videoNaNNaNNone$0[{'description': None, 'address1': '8536 Natio...
\n", + "
" + ], + "text/plain": [ + " name category_code number_of_employees founded_year deadpooled_year \\\n", + "0 Digg news 60.0 2004.0 None \n", + "1 Facebook social 5299.0 2004.0 None \n", + "2 Postini web NaN 1999.0 None \n", + "3 Geni web 18.0 2006.0 None \n", + "4 Flektor games_video NaN NaN None \n", + "\n", + " total_money_raised offices \n", + "0 $45M [{'description': None, 'address1': '135 Missis... \n", + "1 $2.43B [{'description': 'Headquarters', 'address1': '... \n", + "2 $0 [{'description': None, 'address1': '959 Skyway... \n", + "3 $16.5M [{'description': 'Headquarters', 'address1': '... \n", + "4 $0 [{'description': None, 'address1': '8536 Natio... " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Selecting only the ones that have offices and do not have deadpool year\n", + "cole = col.find({'offices': {'$not': {'$size':0}},\n", + " 'deadpooled_year':{'$type':'null'}},\n", + " {'_id':0 ,'name':1,'category_code':1,'number_of_employees':1,\n", + " 'offices':1,'founded_year':1,'deadpooled_year':1,'total_money_raised':1})\n", + "data = pd.DataFrame(cole)\n", + "data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 12957 entries, 0 to 12956\n", + "Data columns (total 7 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 name 12957 non-null object \n", + " 1 category_code 12310 non-null object \n", + " 2 number_of_employees 7039 non-null float64\n", + " 3 founded_year 10630 non-null float64\n", + " 4 deadpooled_year 0 non-null object \n", + " 5 total_money_raised 12957 non-null object \n", + " 6 offices 12957 non-null object \n", + "dtypes: float64(2), object(5)\n", + "memory usage: 708.7+ KB\n" + ] + } + ], + "source": [ + "data.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(12957, 7)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 3\n", + "#### Transforming data according to client needs" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 12957/12957 [02:05<00:00, 102.86it/s]\n" + ] + } + ], + "source": [ + "#Generate a list with dataframes with office information.\n", + "#adding a column with name, total employees, category and number of offices\n", + "\n", + "lista_df=[] \n", + "\n", + "for i in tqdm(range(len(data.offices))):\n", + " df = pd.DataFrame(data.iloc[i].offices)\n", + " df['name'] = str(data.loc[i,['name'][0]])\n", + " df['total_employees'] = data.iloc[i].number_of_employees\n", + " df['category'] = str(data.loc[i,['category_code'][0]])\n", + " df['total_offices'] = len(data.iloc[i].offices)\n", + " lista_df.append(df)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12957" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(lista_df)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_employeescategorytotal_offices
0None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395Digg60.0news1
1Headquarters1601 Willow Road94025Menlo ParkCAUSA37.416-122.152Facebook5299.0social3
2Europe HQDublinNoneIRL53.3441-6.26749Facebook5299.0social3
3New York340 Madison Ave10017New YorkNYUSA40.7557-73.9792Facebook5299.0social3
4None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248PostiniNaNweb1
\n", + "
" + ], + "text/plain": [ + " description address1 address2 zip_code city \\\n", + "0 None 135 Mississippi St 94107 San Francisco \n", + "1 Headquarters 1601 Willow Road 94025 Menlo Park \n", + "2 Europe HQ Dublin \n", + "3 New York 340 Madison Ave 10017 New York \n", + "4 None 959 Skyway Road, Suite 200 None 94070 San Carlos \n", + "\n", + " state_code country_code latitude longitude name total_employees \\\n", + "0 CA USA 37.7647 -122.395 Digg 60.0 \n", + "1 CA USA 37.416 -122.152 Facebook 5299.0 \n", + "2 None IRL 53.3441 -6.26749 Facebook 5299.0 \n", + "3 NY USA 40.7557 -73.9792 Facebook 5299.0 \n", + "4 CA USA 37.5069 -122.248 Postini NaN \n", + "\n", + " category total_offices \n", + "0 news 1 \n", + "1 social 3 \n", + "2 social 3 \n", + "3 social 3 \n", + "4 web 1 " + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final = pd.concat(lista_df).reset_index(drop=True)\n", + "final.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15848, 13)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "country_code\n", + "USA 9652\n", + "GBR 1327\n", + "CAN 591\n", + "IND 509\n", + "DEU 392\n", + "FRA 359\n", + "AUS 263\n", + "ESP 232\n", + "ISR 213\n", + "CHN 196\n", + "Name: name, dtype: int64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.groupby('country_code')['name'].count().sort_values(ascending=False).head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 15848/15848 [00:01<00:00, 8747.27it/s]\n" + ] + } + ], + "source": [ + "#genero una lista con los geopuntos en formato de diccionario\n", + "lista_points = []\n", + "for i in tqdm(range(len(final.longitude))):\n", + " \n", + " lista_points.append(dict({'type':'Point',\n", + " 'coordinates': [final.longitude[i],\n", + " final.latitude[i]]}))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15848" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(lista_points)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "#agrego los puntos al DataFrame \n", + "final['principal'] = pd.Series(lista_points)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['description', 'address1', 'address2', 'zip_code', 'city', 'state_code',\n", + " 'country_code', 'latitude', 'longitude', 'name', 'total_employees',\n", + " 'category', 'total_offices', 'principal'],\n", + " dtype='object')" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15848, 14)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "#reordeno el dataframe\n", + "final = final[['name','total_employees','category','total_offices','description','address1',\n", + " 'address2','zip_code','city','state_code','country_code','latitude','longitude','principal']]" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nametotal_employeescategorytotal_officesdescriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudeprincipalcompany_size
0Digg60.0news1None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395{'type': 'Point', 'coordinates': [-122.394523,...SMB
1Facebook5299.0social3Headquarters1601 Willow Road94025Menlo ParkCAUSA37.416-122.152{'type': 'Point', 'coordinates': [-122.151801,...JUMBO
2Facebook5299.0social3Europe HQDublinNoneIRL53.3441-6.26749{'type': 'Point', 'coordinates': [-6.267494, 5...JUMBO
3Facebook5299.0social3New York340 Madison Ave10017New YorkNYUSA40.7557-73.9792{'type': 'Point', 'coordinates': [-73.9792469,...JUMBO
4PostiniNaNweb1None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248{'type': 'Point', 'coordinates': [-122.247573,...SMB
\n", + "
" + ], + "text/plain": [ + " name total_employees category total_offices description \\\n", + "0 Digg 60.0 news 1 None \n", + "1 Facebook 5299.0 social 3 Headquarters \n", + "2 Facebook 5299.0 social 3 Europe HQ \n", + "3 Facebook 5299.0 social 3 New York \n", + "4 Postini NaN web 1 None \n", + "\n", + " address1 address2 zip_code city state_code \\\n", + "0 135 Mississippi St 94107 San Francisco CA \n", + "1 1601 Willow Road 94025 Menlo Park CA \n", + "2 Dublin None \n", + "3 340 Madison Ave 10017 New York NY \n", + "4 959 Skyway Road, Suite 200 None 94070 San Carlos CA \n", + "\n", + " country_code latitude longitude \\\n", + "0 USA 37.7647 -122.395 \n", + "1 USA 37.416 -122.152 \n", + "2 IRL 53.3441 -6.26749 \n", + "3 USA 40.7557 -73.9792 \n", + "4 USA 37.5069 -122.248 \n", + "\n", + " principal company_size \n", + "0 {'type': 'Point', 'coordinates': [-122.394523,... SMB \n", + "1 {'type': 'Point', 'coordinates': [-122.151801,... JUMBO \n", + "2 {'type': 'Point', 'coordinates': [-6.267494, 5... JUMBO \n", + "3 {'type': 'Point', 'coordinates': [-73.9792469,... JUMBO \n", + "4 {'type': 'Point', 'coordinates': [-122.247573,... SMB " + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#agrego columna JUMBO o SMB dependiendo de la cantidad de empleados\n", + "final['company_size'] = np.where(final.total_employees>1000,'JUMBO','SMB')\n", + "\n", + "final.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nametotal_employeescategorytotal_officesdescriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudeprincipalcompany_size
0Digg60.0news1None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395{'type': 'Point', 'coordinates': [-122.394523,...SMB
4PostiniNaNweb1None959 Skyway Road, Suite 200None94070San CarlosCAUSA37.5069-122.248{'type': 'Point', 'coordinates': [-122.247573,...SMB
5Geni18.0web1Headquarters9229 W. Sunset Blvd.90069West HollywoodCAUSA34.0904-118.393{'type': 'Point', 'coordinates': [-118.393064,...SMB
6FlektorNaNgames_video1None8536 National Blvd, Suite ANone90232Culver CityCAUSA34.026-118.38{'type': 'Point', 'coordinates': [-118.379768,...SMB
7Fox Interactive Media0.0web1407 N Maple Dr90210Beverly HillsCAUSA34.0762-118.394{'type': 'Point', 'coordinates': [-118.39417, ...SMB
\n", + "
" + ], + "text/plain": [ + " name total_employees category total_offices \\\n", + "0 Digg 60.0 news 1 \n", + "4 Postini NaN web 1 \n", + "5 Geni 18.0 web 1 \n", + "6 Flektor NaN games_video 1 \n", + "7 Fox Interactive Media 0.0 web 1 \n", + "\n", + " description address1 address2 zip_code \\\n", + "0 None 135 Mississippi St 94107 \n", + "4 None 959 Skyway Road, Suite 200 None 94070 \n", + "5 Headquarters 9229 W. Sunset Blvd. 90069 \n", + "6 None 8536 National Blvd, Suite A None 90232 \n", + "7 407 N Maple Dr 90210 \n", + "\n", + " city state_code country_code latitude longitude \\\n", + "0 San Francisco CA USA 37.7647 -122.395 \n", + "4 San Carlos CA USA 37.5069 -122.248 \n", + "5 West Hollywood CA USA 34.0904 -118.393 \n", + "6 Culver City CA USA 34.026 -118.38 \n", + "7 Beverly Hills CA USA 34.0762 -118.394 \n", + "\n", + " principal company_size \n", + "0 {'type': 'Point', 'coordinates': [-122.394523,... SMB \n", + "4 {'type': 'Point', 'coordinates': [-122.247573,... SMB \n", + "5 {'type': 'Point', 'coordinates': [-118.393064,... SMB \n", + "6 {'type': 'Point', 'coordinates': [-118.379768,... SMB \n", + "7 {'type': 'Point', 'coordinates': [-118.39417, ... SMB " + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#elimino a las empresas JUMBO\n", + "final = final[final.company_size == 'SMB']\n", + "final.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15383, 15)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "final.dropna(subset=['latitude','longitude'],inplace=True) " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(9919, 15)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 4\n", + "#### Create a new collection with the final DataFrame in MongoCompass so we can add a 2dsphere index. " + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#inserto en compass el data frame resultante en una nueva coleccion\n", + "db.project.insert_many(final.to_dict('records')) " + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'principal_2dsphere'" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#creo el índice 2dsphere para poder hacer geoqueries\n", + "db.project.create_index([('principal', '2dsphere')])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 5\n", + "\n", + "#### Make geoqueries of the new collection with client conditions" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "cole = db.project" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "#funcion que me permite encontrar puntos cercanos con radio por default de 1000 metros\n", + "def find_near(geopoint, radio=10000):\n", + " \n", + " return cole.find({'principal':{\n", + " '$near': {'$geometry': geopoint, '$maxDistance':radio}\n", + " }})" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "#inicializo la conexión con geocoder\n", + "key = 'd8314354b31d46a298e0f21ffb920a34'\n", + "geocoder = OpenCageGeocode(key)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "#función que permite al usuario elegir una dirección y en base a la misma devuelve los datos necesarios para hacer la geoquery\n", + "def getting_coor():\n", + " try:\n", + " 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", + " localidad = country+', '+city\n", + " fcoordinates.append(coordinates)\n", + " fcoordinates.append(m)\n", + " fcoordinates.append(localidad)\n", + " fcoordinates.append(x)\n", + " fcoordinates.append(bandera)\n", + " return fcoordinates\n", + " except:\n", + " return 'Not a valid address'" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? San Diego California\n", + "Whats the max distance you would like to evaluate: 2500\n", + "Amount of offices near San Diego California are: 24\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#este podría ser el código principal que solicita el input del usuario y devuelve el mapa\n", + "\n", + "coordenadas = getting_coor() #acá inicializa la funcion creada arriba\n", + "longlat = coordenadas[0]\n", + "latlong = longlat[::-1]\n", + "radio = int(coordenadas[1])\n", + "pais = coordenadas[4]\n", + "localidad = coordenadas[2]\n", + "direccion_solicitud = coordenadas[3]\n", + "\n", + "address={'type': 'Point', 'coordinates':longlat} # geopoint\n", + "\n", + "ratio=radio # radio de busqueda\n", + "\n", + "n_ofi=find_near(address, ratio).count()\n", + "ofi = find_near(address, ratio)\n", + "ofi=pd.DataFrame(ofi)\n", + "\n", + "#creating map object\n", + "tooltip = 'Location you chose: {} \\n {}'.format(direccion_solicitud,localidad)\n", + "mapa=folium.Map(latlong, zoom_start=12, width='100%', height='100%')\n", + "datamapa=ofi[['latitude', 'longitude']].values\n", + "mapa.add_child(plugins.HeatMap(datamapa, radius=15))\n", + "folium.Marker(latlong, tooltip=tooltip, icon=folium.Icon()).add_to(mapa)\n", + "mapa.save('MapaFinal.html')\n", + "print('Amount of offices near {} are: {}'.format(direccion_solicitud,n_ofi))\n", + "mapa\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 6\n", + "#### Get more information about restaurants in the area and display them with the heatmap mentioned above and marking where the restaurants of coffee shops are. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Found a DB in Kaggle with California restaurants. I proceed to explore and clean data" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "#https://www.kaggle.com/vaibhavsxn/restaurants-in-california\n", + "\n", + "with open('rest_data_ca.pkl', 'rb') as rest:\n", + " data = pickle.load(rest)\n", + " \n", + "dfrest = pd.DataFrame(data)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Int64Index: 52477 entries, 0 to 56157\n", + "Data columns (total 6 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Cuisine 52477 non-null object\n", + " 1 address 52477 non-null object\n", + " 2 name 52477 non-null object\n", + " 3 postalCode 52477 non-null object\n", + " 4 Tag 52477 non-null object\n", + " 5 ratings 52477 non-null int64 \n", + "dtypes: int64(1), object(5)\n", + "memory usage: 2.8+ MB\n" + ] + } + ], + "source": [ + "dfrest.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "All 47851\n", + "Mexican 4530\n", + "Fast Food 64\n", + "Veg 32\n", + "Name: Cuisine, dtype: int64" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.Cuisine.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Food 52477\n", + "Name: Tag, dtype: int64" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.Tag.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4 26428\n", + "3 26049\n", + "Name: ratings, dtype: int64" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.ratings.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratings
0Fast Food925 Blossom Hill Road Oakridge MallBuca Di Beppo - San Jose - Oakridge95123Food4
1Fast Food555 Soquel AveRistorante Italiano95062Food4
2Fast Food9822 Libra AveMilanos Pizza95827Food4
3Fast Food1640 Camino Del Rio NTilted Kilt Mission Valley92108Food4
4Fast Food1231 Park StThe Fire Den94501Food4
.....................
26423All6719 LA TIJERA BLVD # A-BCHIPOTLE #309490045Food4
26424All100 1/2 7TH STBRAAZO PIZZA90014Food4
26425All1244 WESTWOOD BLVDPOKE'ME90024Food4
26426All217 W TEMPLE AVEHALL OF JUSTICE90012Food4
26427All6741 HOLLYWOOD BLVDJUICY WINGZ90028Food4
\n", + "

26428 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " Cuisine address \\\n", + "0 Fast Food 925 Blossom Hill Road Oakridge Mall \n", + "1 Fast Food 555 Soquel Ave \n", + "2 Fast Food 9822 Libra Ave \n", + "3 Fast Food 1640 Camino Del Rio N \n", + "4 Fast Food 1231 Park St \n", + "... ... ... \n", + "26423 All 6719 LA TIJERA BLVD # A-B \n", + "26424 All 100 1/2 7TH ST \n", + "26425 All 1244 WESTWOOD BLVD \n", + "26426 All 217 W TEMPLE AVE \n", + "26427 All 6741 HOLLYWOOD BLVD \n", + "\n", + " name postalCode Tag ratings \n", + "0 Buca Di Beppo - San Jose - Oakridge 95123 Food 4 \n", + "1 Ristorante Italiano 95062 Food 4 \n", + "2 Milanos Pizza 95827 Food 4 \n", + "3 Tilted Kilt Mission Valley 92108 Food 4 \n", + "4 The Fire Den 94501 Food 4 \n", + "... ... ... ... ... \n", + "26423 CHIPOTLE #3094 90045 Food 4 \n", + "26424 BRAAZO PIZZA 90014 Food 4 \n", + "26425 POKE'ME 90024 Food 4 \n", + "26426 HALL OF JUSTICE 90012 Food 4 \n", + "26427 JUICY WINGZ 90028 Food 4 \n", + "\n", + "[26428 rows x 6 columns]" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#removing restaurants with low ratings\n", + "dfrest = dfrest[dfrest.ratings>=4]\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "# Using REGEX so I can categorize the restaurant type\n", + "\n", + "def typerest(x):\n", + " if re.search(r'pizza',x.lower()) or re.search(r'pasta',x.lower()) or re.search(r'italia',x.lower()):\n", + " x='Italian'\n", + " elif re.search(r'burger',x.lower()):\n", + " x='Burger'\n", + " elif re.search(r'coffee',x.lower()):\n", + " x='CoffeeShop'\n", + " elif re.search(r'coffee',x.lower()):\n", + " x='CoffeeShop'\n", + " elif re.search(r'pie',x.lower()) or re.search(r'cake',x.lower()) or re.search(r'dess?ert',x.lower()):\n", + " x='Dessert'\n", + " elif re.search(r'mex',x.lower()) or re.search(r'taco',x.lower()):\n", + " x='Mexican'\n", + " elif re.search(r'sushi',x.lower()) or re.search(r'poke',x.lower()) or re.search(r'dumpling',x.lower())\\\n", + " or re.search(r'asia',x.lower()) or re.search(r'china?e?',x.lower()) or re.search(r'japan',x.lower())\\\n", + " or re.search(r'korea',x.lower()):\n", + " x='Asian'\n", + " else:\n", + " x='other'\n", + " \n", + " return x " + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 26428/26428 [00:00<00:00, 27249.91it/s]\n" + ] + } + ], + "source": [ + "#applying the above function to the data frame using TQDM\n", + "tqdm.pandas()\n", + "dfrest['type'] = dfrest['name'].progress_apply(typerest)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0Fast Food925 Blossom Hill Road Oakridge MallBuca Di Beppo - San Jose - Oakridge95123Food4other
1Fast Food555 Soquel AveRistorante Italiano95062Food4Italian
2Fast Food9822 Libra AveMilanos Pizza95827Food4Italian
3Fast Food1640 Camino Del Rio NTilted Kilt Mission Valley92108Food4other
4Fast Food1231 Park StThe Fire Den94501Food4other
\n", + "
" + ], + "text/plain": [ + " Cuisine address \\\n", + "0 Fast Food 925 Blossom Hill Road Oakridge Mall \n", + "1 Fast Food 555 Soquel Ave \n", + "2 Fast Food 9822 Libra Ave \n", + "3 Fast Food 1640 Camino Del Rio N \n", + "4 Fast Food 1231 Park St \n", + "\n", + " name postalCode Tag ratings type \n", + "0 Buca Di Beppo - San Jose - Oakridge 95123 Food 4 other \n", + "1 Ristorante Italiano 95062 Food 4 Italian \n", + "2 Milanos Pizza 95827 Food 4 Italian \n", + "3 Tilted Kilt Mission Valley 92108 Food 4 other \n", + "4 The Fire Den 94501 Food 4 other " + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "other 22147\n", + "Mexican 1165\n", + "Asian 929\n", + "Italian 833\n", + "CoffeeShop 632\n", + "Burger 552\n", + "Dessert 170\n", + "Name: type, dtype: int64" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.type.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0Fast Food555 Soquel AveRistorante Italiano95062Food4Italian
1Fast Food9822 Libra AveMilanos Pizza95827Food4Italian
2Fast Food5365 Alton PkwyZpizza92604Food4Italian
3Fast Food6593 Collins DrCustom Pie93021Food4Dessert
4Fast Food820 N Alta AveYou-be's U-bake Pizza93618Food4Italian
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode Tag \\\n", + "0 Fast Food 555 Soquel Ave Ristorante Italiano 95062 Food \n", + "1 Fast Food 9822 Libra Ave Milanos Pizza 95827 Food \n", + "2 Fast Food 5365 Alton Pkwy Zpizza 92604 Food \n", + "3 Fast Food 6593 Collins Dr Custom Pie 93021 Food \n", + "4 Fast Food 820 N Alta Ave You-be's U-bake Pizza 93618 Food \n", + "\n", + " ratings type \n", + "0 4 Italian \n", + "1 4 Italian \n", + "2 4 Italian \n", + "3 4 Dessert \n", + "4 4 Italian " + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Because of the request number restriction, \n", + "#Im deleting every \"other\" type restaurant in database\n", + "dfrest = dfrest[dfrest.type != 'other']\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstype
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type \n", + "0 Food 4 Mexican \n", + "1 Food 4 Burger \n", + "2 Food 4 Burger \n", + "3 Food 4 Mexican \n", + "4 Food 4 Burger " + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#getting a sample of 2000 restaurantes because of api restriction\n", + "dfrest = dfrest.sample(2000)\n", + "dfrest.reset_index(drop = True, inplace = True)\n", + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2000, 7)" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "#function to obtain latitude and longitude of the addresses in DF\n", + "def gettingres_coor(x):\n", + " try:\n", + " results = geocoder.geocode(x)\n", + " coordinates=[]\n", + " coordinates.append(results[0]['geometry']['lng'])\n", + " coordinates.append(results[0]['geometry']['lat']) \n", + " return coordinates\n", + " except:\n", + " return np.nan" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 2000/2000 [39:35<00:00, 1.19s/it] \n" + ] + } + ], + "source": [ + "#applying function to DF\n", + "tqdm.pandas()\n", + "dfrest['coordinates'] = dfrest.address.progress_apply(gettingres_coor)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "#removing nan values\n", + "dfrest.dropna(inplace=True)\n", + "dfrest.reset_index(drop = True, inplace = True)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "#splitting columns\n", + "dfrest['latitude'] = dfrest.coordinates.apply(lambda x:x[1])\n", + "dfrest['longitude'] = dfrest.coordinates.apply(lambda x:x[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitude
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican[-117.7520488, 34.0684236]34.068424-117.752049
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger[-118.3018267, 34.1799755]34.179975-118.301827
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger[-118.0734294, 34.0840807]34.084081-118.073429
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican[-118.5031071, 34.2285216]34.228522-118.503107
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger[-75.926111, 42.105103]42.105103-75.926111
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type coordinates latitude longitude \n", + "0 Food 4 Mexican [-117.7520488, 34.0684236] 34.068424 -117.752049 \n", + "1 Food 4 Burger [-118.3018267, 34.1799755] 34.179975 -118.301827 \n", + "2 Food 4 Burger [-118.0734294, 34.0840807] 34.084081 -118.073429 \n", + "3 Food 4 Mexican [-118.5031071, 34.2285216] 34.228522 -118.503107 \n", + "4 Food 4 Burger [-75.926111, 42.105103] 42.105103 -75.926111 " + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 1995/1995 [00:00<00:00, 4321.81it/s]\n" + ] + } + ], + "source": [ + "#getting a list of the geopoints\n", + "lista_pointsres = []\n", + "for i in tqdm(range(len(dfrest.latitude))):\n", + " lista_pointsres.append(dict({'type':'Point',\n", + " 'coordinates': [dfrest.longitude[i],\n", + " dfrest.latitude[i]]}))" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "#adding geopoints to main DF\n", + "dfrest['principal'] = pd.Series(lista_pointsres)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitudeprincipal
0All2068 N GAREY AVEANGELES LA MEJOR MEXICAN FOOD91767Food4Mexican[-117.7520488, 34.0684236]34.068424-117.752049{'type': 'Point', 'coordinates': [-117.7520488...
1All8742 GLENOAKS BLVDOLD TIME BURGERS91352Food4Burger[-118.3018267, 34.1799755]34.179975-118.301827{'type': 'Point', 'coordinates': [-118.3018267...
2All4242 N ROSEMEAD BLVDIN-N-OUT BURGER #2091770Food4Burger[-118.0734294, 34.0840807]34.084081-118.073429{'type': 'Point', 'coordinates': [-118.0734294...
3All15307 PARTHENIA STDANIEL'S TACOS91343Food4Mexican[-118.5031071, 34.2285216]34.228522-118.503107{'type': 'Point', 'coordinates': [-118.5031071...
4All3748 SLAUSON AVEBURGER KING #1129890270Food4Burger[-75.926111, 42.105103]42.105103-75.926111{'type': 'Point', 'coordinates': [-75.926111, ...
\n", + "
" + ], + "text/plain": [ + " Cuisine address name postalCode \\\n", + "0 All 2068 N GAREY AVE ANGELES LA MEJOR MEXICAN FOOD 91767 \n", + "1 All 8742 GLENOAKS BLVD OLD TIME BURGERS 91352 \n", + "2 All 4242 N ROSEMEAD BLVD IN-N-OUT BURGER #20 91770 \n", + "3 All 15307 PARTHENIA ST DANIEL'S TACOS 91343 \n", + "4 All 3748 SLAUSON AVE BURGER KING #11298 90270 \n", + "\n", + " Tag ratings type coordinates latitude longitude \\\n", + "0 Food 4 Mexican [-117.7520488, 34.0684236] 34.068424 -117.752049 \n", + "1 Food 4 Burger [-118.3018267, 34.1799755] 34.179975 -118.301827 \n", + "2 Food 4 Burger [-118.0734294, 34.0840807] 34.084081 -118.073429 \n", + "3 Food 4 Mexican [-118.5031071, 34.2285216] 34.228522 -118.503107 \n", + "4 Food 4 Burger [-75.926111, 42.105103] 42.105103 -75.926111 \n", + "\n", + " principal \n", + "0 {'type': 'Point', 'coordinates': [-117.7520488... \n", + "1 {'type': 'Point', 'coordinates': [-118.3018267... \n", + "2 {'type': 'Point', 'coordinates': [-118.0734294... \n", + "3 {'type': 'Point', 'coordinates': [-118.5031071... \n", + "4 {'type': 'Point', 'coordinates': [-75.926111, ... " + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dfrest.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#inserting to Compass\n", + "db.restaurantes.insert_many(dfrest.to_dict('records')) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'principal_2dsphere'" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#creating 2dsphere index\n", + "db.restaurantes.create_index([('principal', '2dsphere')])" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "#function to find restaurants near clients input\n", + "coleres = db.restaurantes\n", + "def find_near_res(geopoint, radio=10000):\n", + " \n", + " return coleres.find({'principal':{\n", + " '$near': {'$geometry': geopoint, '$maxDistance':radio}\n", + " }})" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Where would you like your office? San Diego California\n", + "Whats the max distance you would like to evaluate: 2500\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 2/2 [00:00<00:00, 411.63it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Amount of offices near San Diego California are: 24\n", + "Amount of restaurants near San Diego California are: 2\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#main code to ask client where they want the office and getting all the needed information\n", + "\n", + "coordenadas = getting_coor() #function discribed above\n", + "longlat = coordenadas[0]\n", + "latlong = longlat[::-1]\n", + "radio = int(coordenadas[1])\n", + "pais = coordenadas[4]\n", + "localidad = coordenadas[2]\n", + "direccion_solicitud = coordenadas[3]\n", + "\n", + "address={'type': 'Point', 'coordinates':longlat} # geopoint\n", + "\n", + "ratio=radio # radio de busqueda\n", + "\n", + "#query for offices\n", + "n_ofi=find_near(address, ratio).count()\n", + "ofi = find_near(address, ratio)\n", + "ofi=pd.DataFrame(ofi)\n", + "\n", + "#query for restaurants\n", + "n_res=find_near_res(address, ratio).count()\n", + "restaurant = find_near_res(address, ratio)\n", + "restaurant = pd.DataFrame(restaurant)\n", + "\n", + "#creating map object\n", + "tooltip = 'Location you chose: {} \\n {}'.format(direccion_solicitud,localidad)\n", + "mapa=folium.Map(latlong, zoom_start=11)\n", + "datamapa=ofi[['latitude', 'longitude']].values\n", + "mapa.add_child(plugins.HeatMap(datamapa, radius=15))\n", + "folium.Marker(latlong, tooltip=tooltip, icon=folium.Icon(color='red')).add_to(mapa)\n", + "for i in trange(len(restaurant.latitude)):\n", + " folium.Marker([restaurant.latitude[i],restaurant.longitude[i]],\n", + " tooltip = restaurant.name[i], icon = folium.Icon()).add_to(mapa)\n", + "\n", + "mapa.save('MapaFinalRestaurantes.html')\n", + "print('Amount of offices near {} are: {}'.format(direccion_solicitud,n_ofi))\n", + "print('Amount of restaurants near {} are: {}'.format(direccion_solicitud,n_res))\n", + "mapa" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idCuisineaddressnamepostalCodeTagratingstypecoordinateslatitudelongitudeprincipal
05e9db680e283983c43b35a8eAll740 W BROADWAYFRANK'S BURGER91204Food4Burger[-117.1701501, 32.7156373]32.715637-117.17015{'type': 'Point', 'coordinates': [-117.1701501...
15e9db680e283983c43b35e67All3995 24th StSTARBUCKS COFFEE #54594114Food4CoffeeShop[-117.14241, 32.706318]32.706318-117.14241{'type': 'Point', 'coordinates': [-117.14241, ...
\n", + "
" + ], + "text/plain": [ + " _id Cuisine address name \\\n", + "0 5e9db680e283983c43b35a8e All 740 W BROADWAY FRANK'S BURGER \n", + "1 5e9db680e283983c43b35e67 All 3995 24th St STARBUCKS COFFEE #545 \n", + "\n", + " postalCode Tag ratings type coordinates \\\n", + "0 91204 Food 4 Burger [-117.1701501, 32.7156373] \n", + "1 94114 Food 4 CoffeeShop [-117.14241, 32.706318] \n", + "\n", + " latitude longitude principal \n", + "0 32.715637 -117.17015 {'type': 'Point', 'coordinates': [-117.1701501... \n", + "1 32.706318 -117.14241 {'type': 'Point', 'coordinates': [-117.14241, ... " + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "restaurant.head()" + ] + }, + { + "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/README.md b/module-2/python-bi-project/python-bi-project - Esteban/README.md new file mode 100644 index 0000000..7c58d7b --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/README.md @@ -0,0 +1,43 @@ +# Python BI Project + +### The following project consists in finding an office space for a Digital Marketing Agency + +Main code asks the user for an address or location where they want to search or evaluate if its optimal for their office. + +There are some limitations: + They want to be sorrounded with Small and Medium Business + They want to have a coffee shop nearby + They want to be in San Diego California + +### For this project I'm using the following libraries: + ++ Pandas ++ Pymongo ++ TQDM ++ Folium ++ Numpy ++ Warnings ++ Regex ++ Pickle ++ OpenCage (for geocode) + + +### In order to achieve the main result, I'm folowing 6 steps: + +#### Step 1 +Define client type: as I mentioned in the README ,they want to be sorrounded with Small and Medium Business, they want to have a coffee shop nearby and they want to be in San Diego California + +#### Step 2 +Correctly query the data I want from Mongo. + +#### Step 3 +Transforming data according to client needs. + +#### Step 4 +Create a new collection with the final DataFrame in MongoCompass so we can add a 2dsphere index. + +#### Step 5 +Make geoqueries of the new collection with client input and display them in a heatmap reflecting the concentration of offices in the selected area. + +#### Step 6 +Get more information about restaurants in the area and display them with the heatmap mentioned above and marking where the restaurants of coffee shops are. \ No newline at end of file diff --git a/module-2/python-bi-project/python-bi-project - Esteban/draft.ipynb b/module-2/python-bi-project/python-bi-project - Esteban/draft.ipynb new file mode 100644 index 0000000..be3e1a0 --- /dev/null +++ b/module-2/python-bi-project/python-bi-project - Esteban/draft.ipynb @@ -0,0 +1,3121 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import pymongo\n", + "from pymongo import MongoClient" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "cliente=MongoClient('mongodb://localhost:27017')\n", + "db = cliente.companies\n", + "col = db.companies\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idnamepermalinkcrunchbase_urlhomepage_urlblog_urlblog_feed_urltwitter_usernamecategory_codenumber_of_employees...officesmilestonesvideo_embedsscreenshotsexternal_linkspartnersdeadpooled_monthdeadpooled_daydeadpooled_urlipo
052cdef7c4bab8bd675297d8aWetpaintabc2http://www.crunchbase.com/company/wetpainthttp://wetpaint-inc.comhttp://digitalquarters.net/http://digitalquarters.net/feed/BachelrWetpaintweb47.0...[{'description': '', 'address1': '710 - 2nd Av...[{'id': 5869, 'description': 'Wetpaint named i...[][{'available_sizes': [[[150, 86], 'assets/imag...[{'external_url': 'http://www.geekwire.com/201...[]NaNNaNNaNNaN
152cdef7c4bab8bd675297d8bAdventNetabc3http://www.crunchbase.com/company/adventnethttp://adventnet.commanageengineenterprise600.0...[{'description': 'Headquarters', 'address1': '...[][][{'available_sizes': [[[150, 94], 'assets/imag...[][]NaNNaNNaNNaN
252cdef7c4bab8bd675297d8cZohoabc4http://www.crunchbase.com/company/zohohttp://zoho.comhttp://blogs.zoho.com/http://blogs.zoho.com/feedzohosoftware1600.0...[{'description': 'Headquarters', 'address1': '...[{'id': 388, 'description': 'Zoho Reaches 2 Mi...[{'embed_code': '<object width=\"430\" height=\"2...[][{'external_url': 'http://www.online-tech-tips...[]NaNNaNNaNNaN
352cdef7c4bab8bd675297d8dDiggdigghttp://www.crunchbase.com/company/digghttp://www.digg.comhttp://blog.digg.com/http://blog.digg.com/?feed=rss2diggnews60.0...[{'description': None, 'address1': '135 Missis...[{'id': 9588, 'description': 'Another Digg Exe...[{'embed_code': '<embed src=\"http://blip.tv/pl...[{'available_sizes': [[[117, 150], 'assets/ima...[{'external_url': 'http://www.sociableblog.com...[]NaNNaNNoneNone
452cdef7c4bab8bd675297d8eFacebookfacebookhttp://www.crunchbase.com/company/facebookhttp://facebook.comhttp://blog.facebook.comhttp://blog.facebook.com/atom.phpfacebooksocial5299.0...[{'description': 'Headquarters', 'address1': '...[{'id': 108, 'description': 'Facebook adds com...[][{'available_sizes': [[[150, 68], 'assets/imag...[{'external_url': 'http://latimesblogs.latimes...[]NaNNaN{'valuation_amount': 104000000000, 'valuation_...
\n", + "

5 rows × 42 columns

\n", + "
" + ], + "text/plain": [ + " _id name permalink \\\n", + "0 52cdef7c4bab8bd675297d8a Wetpaint abc2 \n", + "1 52cdef7c4bab8bd675297d8b AdventNet abc3 \n", + "2 52cdef7c4bab8bd675297d8c Zoho abc4 \n", + "3 52cdef7c4bab8bd675297d8d Digg digg \n", + "4 52cdef7c4bab8bd675297d8e Facebook facebook \n", + "\n", + " crunchbase_url homepage_url \\\n", + "0 http://www.crunchbase.com/company/wetpaint http://wetpaint-inc.com \n", + "1 http://www.crunchbase.com/company/adventnet http://adventnet.com \n", + "2 http://www.crunchbase.com/company/zoho http://zoho.com \n", + "3 http://www.crunchbase.com/company/digg http://www.digg.com \n", + "4 http://www.crunchbase.com/company/facebook http://facebook.com \n", + "\n", + " blog_url blog_feed_url \\\n", + "0 http://digitalquarters.net/ http://digitalquarters.net/feed/ \n", + "1 \n", + "2 http://blogs.zoho.com/ http://blogs.zoho.com/feed \n", + "3 http://blog.digg.com/ http://blog.digg.com/?feed=rss2 \n", + "4 http://blog.facebook.com http://blog.facebook.com/atom.php \n", + "\n", + " twitter_username category_code number_of_employees ... \\\n", + "0 BachelrWetpaint web 47.0 ... \n", + "1 manageengine 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': '... \n", + "\n", + " milestones \\\n", + "0 [{'id': 5869, 'description': 'Wetpaint named i... \n", + "1 [] \n", + "2 [{'id': 388, 'description': 'Zoho Reaches 2 Mi... \n", + "3 [{'id': 9588, 'description': 'Another Digg Exe... \n", + "4 [{'id': 108, 'description': 'Facebook adds com... \n", + "\n", + " video_embeds \\\n", + "0 [] \n", + "1 [] \n", + "2 [{'embed_code': '\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_idnamepermalinkcrunchbase_urlhomepage_urlblog_urlblog_feed_urltwitter_usernamecategory_codenumber_of_employees...investmentsacquisitionacquisitionsofficesmilestonesipovideo_embedsscreenshotsexternal_linkspartners
052cdef7c4bab8bd675297d8eFacebookfacebookhttp://www.crunchbase.com/company/facebookhttp://facebook.comhttp://blog.facebook.comhttp://blog.facebook.com/atom.phpfacebooksocial5299...[{'funding_round': {'round_code': 'seed', 'sou...None[{'price_amount': None, 'price_currency_code':...[{'description': 'Headquarters', 'address1': '...[{'id': 108, 'description': 'Facebook adds com...{'valuation_amount': 104000000000, 'valuation_...[][{'available_sizes': [[[150, 68], 'assets/imag...[{'external_url': 'http://latimesblogs.latimes...[]
\n", + "

1 rows × 42 columns

\n", + "" + ], + "text/plain": [ + " _id name permalink \\\n", + "0 52cdef7c4bab8bd675297d8e Facebook facebook \n", + "\n", + " crunchbase_url homepage_url \\\n", + "0 http://www.crunchbase.com/company/facebook http://facebook.com \n", + "\n", + " blog_url blog_feed_url \\\n", + "0 http://blog.facebook.com http://blog.facebook.com/atom.php \n", + "\n", + " twitter_username category_code number_of_employees ... \\\n", + "0 facebook social 5299 ... \n", + "\n", + " investments acquisition \\\n", + "0 [{'funding_round': {'round_code': 'seed', 'sou... None \n", + "\n", + " acquisitions \\\n", + "0 [{'price_amount': None, 'price_currency_code':... \n", + "\n", + " offices \\\n", + "0 [{'description': 'Headquarters', 'address1': '... \n", + "\n", + " milestones \\\n", + "0 [{'id': 108, 'description': 'Facebook adds com... \n", + "\n", + " ipo video_embeds \\\n", + "0 {'valuation_amount': 104000000000, 'valuation_... [] \n", + "\n", + " screenshots \\\n", + "0 [{'available_sizes': [[[150, 68], 'assets/imag... \n", + "\n", + " external_links partners \n", + "0 [{'external_url': 'http://latimesblogs.latimes... [] \n", + "\n", + "[1 rows x 42 columns]" + ] + }, + "execution_count": 226, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cole = col.find({'name':'Facebook'})\n", + "data = pd.DataFrame(cole)\n", + "data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 232, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'description': 'Headquarters',\n", + " 'address1': '1601 Willow Road',\n", + " 'address2': '',\n", + " 'zip_code': '94025',\n", + " 'city': 'Menlo Park',\n", + " 'state_code': 'CA',\n", + " 'country_code': 'USA',\n", + " 'latitude': 37.41605,\n", + " 'longitude': -122.151801},\n", + " {'description': 'Europe HQ',\n", + " 'address1': '',\n", + " 'address2': '',\n", + " 'zip_code': '',\n", + " 'city': 'Dublin',\n", + " 'state_code': None,\n", + " 'country_code': 'IRL',\n", + " 'latitude': 53.344104,\n", + " 'longitude': -6.267494},\n", + " {'description': 'New York',\n", + " 'address1': '340 Madison Ave',\n", + " 'address2': '',\n", + " 'zip_code': '10017',\n", + " 'city': 'New York',\n", + " 'state_code': 'NY',\n", + " 'country_code': 'USA',\n", + " 'latitude': 40.7557162,\n", + " 'longitude': -73.9792469}]" + ] + }, + "execution_count": 232, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.offices[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "len(data.offices[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "_id 52cdef7c4bab8bd675297dba\n", + "name Google\n", + "permalink google\n", + "crunchbase_url http://www.crunchbase.com/company/google\n", + "homepage_url http://google.com\n", + "blog_url http://googleblog.blogspot.com\n", + "blog_feed_url http://googleblog.blogspot.com/feeds/posts/def...\n", + "twitter_username google\n", + "category_code search\n", + "number_of_employees 28000\n", + "founded_year 1998\n", + "founded_month 9\n", + "founded_day 7\n", + "deadpooled_year NaN\n", + "tag_list search, gmail, blogger, find, information, you...\n", + "alias_list Google\n", + "email_address google@google.com\n", + "phone_number 650.253.0000\n", + "description \n", + "created_at Sat Jun 30 22:18:12 UTC 2007\n", + "updated_at Mon Jan 06 04:52:54 UTC 2014\n", + "overview

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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_number_of_employeescategoryprincipal
0Google Headquarters1600 Amphitheatre ParkwayMountain ViewCAUSA37.421972-122.084143Google28000.0search{'type': 'Point', 'coordinates': [-122.084143,...
1Google Ann Arbor112 S. Main St.2nd Floor48104Ann ArborMIUSA42.280988-83.748882Google28000.0search{'type': 'Point', 'coordinates': [-83.748882, ...
2Google Atlanta10 10th Street NESuite 60030309AtlantaGAUSA33.781466-84.387519Google28000.0search{'type': 'Point', 'coordinates': [-84.387519, ...
3Google AustinPlaza 70007000 North MoPac Expressway, 2nd Floor78731AustinTXUSA30.351416-97.751382Google28000.0search{'type': 'Point', 'coordinates': [-97.751382, ...
4Google Boulder2590 Pearl StreetSuite 10080302BoulderCOUSA40.021416-105.260931Google28000.0search{'type': 'Point', 'coordinates': [-105.260931,...
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_number_of_employeescategoryprincipal
0Google Headquarters1600 Amphitheatre ParkwayMountain ViewCAUSA37.421972-122.084143Google28000.0search{'type': 'Point', 'coordinates': [-122.084143,...
1Google Ann Arbor112 S. Main St.2nd Floor48104Ann ArborMIUSA42.280988-83.748882Google28000.0search{'type': 'Point', 'coordinates': [-83.748882, ...
2Google Atlanta10 10th Street NESuite 60030309AtlantaGAUSA33.781466-84.387519Google28000.0search{'type': 'Point', 'coordinates': [-84.387519, ...
3Google AustinPlaza 70007000 North MoPac Expressway, 2nd Floor78731AustinTXUSA30.351416-97.751382Google28000.0search{'type': 'Point', 'coordinates': [-97.751382, ...
4Google Boulder2590 Pearl StreetSuite 10080302BoulderCOUSA40.021416-105.260931Google28000.0search{'type': 'Point', 'coordinates': [-105.260931,...
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namecategory_codenumber_of_employeesoffices
0Wetpaintweb47.0[{'description': '', 'address1': '710 - 2nd Av...
1AdventNetenterprise600.0[{'description': 'Headquarters', 'address1': '...
2Zohosoftware1600.0[{'description': 'Headquarters', 'address1': '...
3Diggnews60.0[{'description': None, 'address1': '135 Missis...
4Facebooksocial5299.0[{'description': 'Headquarters', 'address1': '...
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_employeescategorytotal_offices
0710 - 2nd AvenueSuite 110098104SeattleWAUSA47.6031-122.333Wetpaint47.0web2
1270 Lafayette StreetSuite 50510012New YorkNYUSA40.7237-73.9964Wetpaint47.0web2
2Headquarters4900 Hopyard Rd.Suite 31094588PleasantonCAUSA37.6929-121.905AdventNet600.0enterprise1
3Headquarters4900 Hopyard RdSuite 31094588PleasantonCAUSA37.6929-121.905Zoho1600.0software1
4None135 Mississippi St94107San FranciscoCAUSA37.7647-122.395Digg60.0news1
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
descriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_employeescategorytotal_officesprincipal
0710 - 2nd AvenueSuite 110098104SeattleWAUSA47.6031-122.333Wetpaint47.0web2{'type': 'Point', 'coordinates': [-122.333253,...
1270 Lafayette StreetSuite 50510012New YorkNYUSA40.7237-73.9964Wetpaint47.0web2{'type': 'Point', 'coordinates': [-73.9964312,...
2Headquarters4900 Hopyard Rd.Suite 31094588PleasantonCAUSA37.6929-121.905AdventNet600.0enterprise1{'type': 'Point', 'coordinates': [-121.904945,...
3Headquarters4900 Hopyard RdSuite 31094588PleasantonCAUSA37.6929-121.905Zoho1600.0software1{'type': 'Point', 'coordinates': [-121.904945,...
5Headquarters1601 Willow Road94025Menlo ParkCAUSA37.416-122.152Facebook5299.0social3{'type': 'Point', 'coordinates': [-122.151801,...
.............................................
16677Corporate Headquarters2 Waters Park Drive, #25094403San MateoCAUSA37.5531-122.302NextLabs100.0enterprise1{'type': 'Point', 'coordinates': [-122.301534,...
16687Headquarters89511RenoNVUSA39.3946-119.812MyChances2.0consulting2{'type': 'Point', 'coordinates': [-119.8120795...
16688Menlo Park Office94025Menlo ParkCAUSA37.4485-122.18MyChances2.0consulting2{'type': 'Point', 'coordinates': [-122.1802812...
166972401 East Katella AvenueSuite 30092806-5909AnaheimCAUSA33.8065-117.882Willdan Group385.0other1{'type': 'Point', 'coordinates': [-117.882314,...
16699400 Royal Palm Way33480Palm BeachFLUSA26.7053-80.0414QSGI164.0software1{'type': 'Point', 'coordinates': [-80.041395, ...
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_iddescriptionaddress1address2zip_codecitystate_codecountry_codelatitudelongitudenametotal_employeescategorytotal_officesprincipal
05e9b6c4d54d244e37a3c42c0710 - 2nd AvenueSuite 110098104SeattleWAUSA47.603122-122.333253Wetpaint47.0web2{'type': 'Point', 'coordinates': [-122.333253,...
15e9b6c4d54d244e37a3c42c1270 Lafayette StreetSuite 50510012New YorkNYUSA40.723731-73.996431Wetpaint47.0web2{'type': 'Point', 'coordinates': [-73.9964312,...
25e9b6c4d54d244e37a3c42c2Headquarters4900 Hopyard Rd.Suite 31094588PleasantonCAUSA37.692934-121.904945AdventNet600.0enterprise1{'type': 'Point', 'coordinates': [-121.904945,...
35e9b6c4d54d244e37a3c42c3Headquarters4900 Hopyard RdSuite 31094588PleasantonCAUSA37.692934-121.904945Zoho1600.0software1{'type': 'Point', 'coordinates': [-121.904945,...
45e9b6c4d54d244e37a3c42c4None135 Mississippi St94107San FranciscoCAUSA37.764726-122.394523Digg60.0news1{'type': 'Point', 'coordinates': [-122.394523,...
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
CuisineaddressnamepostalCodeTagratings
0Fast Food925 Blossom Hill Road Oakridge MallBuca Di Beppo - San Jose - Oakridge95123Food4
1Fast Food26900 Newport RdGiovanni's Pizza and Pasta92584Food3
2Fast Food3060 Naglee RdApplebee's Tracy95304Food3
3Fast Food50aPatrick Molloy's Sports Pub90254Food3
4Fast Food555 Soquel AveRistorante Italiano95062Food4
.....................
56153All3470 E 1ST STLA BUFADORA BAR90063Food3
56154All10250 SANTA MONICA BLVD # 1025SAINT MARC90067Food3
56155All217 W TEMPLE AVEHALL OF JUSTICE90012Food4
56156All5750 MELROSE AVEFIN-MELROSE90038Food3
56157All6741 HOLLYWOOD BLVDJUICY WINGZ90028Food4
\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