Skip to content

Instantly share code, notes, and snippets.

@majacaci00
Created September 27, 2016 23:50
Show Gist options
  • Save majacaci00/510d015fd4d719cb38988679071f2e7b to your computer and use it in GitHub Desktop.
Save majacaci00/510d015fd4d719cb38988679071f2e7b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_formats = ['svg']\n",
"sns.set_style(\"white\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"United States of America\n",
"England\n",
"Australia\n",
"Canada\n",
"Germany\n",
"Spain\n",
"France\n",
"Italy\n",
"Ireland\n",
"Netherlands\n",
"Brazil\n",
"Hong Kong\n",
"New Zealand\n",
"Poland\n",
"China\n",
"Finland\n",
"Mexico\n",
"Denmark\n",
"Sweden\n",
"Scotland\n",
"Argentina\n",
"Malaysia\n",
"South Korea\n",
"Belgium\n",
"Switzerland\n",
"Czech Republic\n",
"Austria\n",
"Norway\n",
"Taiwan\n",
"Northern Ireland\n",
"Hungary\n",
"Japan\n",
"Portugal\n",
"Singapore\n",
"Thailand\n",
"Russia\n",
"India\n",
"South Africa\n",
"Chile\n",
"Turkey\n",
"Wales\n",
"Indonesia\n",
"Greece\n",
"Colombia\n",
"Israel\n",
"Romania\n",
"Vietnam\n",
"Slovenia\n",
"Trinidad And Tobago\n",
"Ukraine\n",
"American Samoa\n",
"Costa Rica\n",
"Slovakia\n",
"Lithuania\n",
"Latvia\n",
"Philippines\n",
"Guatemala\n",
"Puerto Rico\n",
"Croatia\n",
"Peru\n",
"Serbia\n",
"Bangladesh\n",
"Venezuela\n",
"Bulgaria\n",
"Tunisia\n",
"Belarus\n",
"Dominican Republic\n",
"Uruguay\n",
"Brunei\n",
"Luxembourg\n",
"Egypt\n",
"Estonia\n",
"Iceland\n",
"Paraguay\n",
"Malta\n",
"Iraq\n",
"Bosnia And Herzegovina\n",
"Armenia\n",
"Mauritius\n",
"Morocco\n",
"Kyrgyzstan\n",
"Kazakhstan\n",
"Bouvet Island\n",
"Jamaica\n",
"Botswana\n",
"Ecuador\n",
"British Virgin Islands\n",
"Pakistan\n",
"Congo\n",
"Iran\n",
"Jordan\n"
]
}
],
"source": [
"## Bing map locators http://bingmapslocators.cloudapp.net/\n",
"# https://geopy.readthedocs.io/en/1.10.0/\n",
"from geopy.geocoders import Bing\n",
"\n",
"countries = ['United States of America', 'England', 'Australia', 'Canada', 'Germany', 'Spain', 'France', 'Italy', 'Ireland', \n",
" 'Netherlands','Brazil',\n",
" 'Hong Kong', 'New Zealand', 'Poland', 'China', 'Finland', 'Mexico', 'Denmark', 'Sweden', 'Scotland', \n",
" 'Argentina',\n",
" 'Malaysia', 'South Korea', 'Belgium', 'Switzerland', 'Czech Republic', 'Austria', 'Norway', 'Taiwan', \n",
" 'Northern Ireland',\n",
" 'Hungary', 'Japan', 'Portugal', 'Singapore', 'Thailand', 'Russia', 'India', 'South Africa', 'Chile', 'Turkey', \n",
" 'Wales', 'Indonesia',\n",
" 'Greece', 'Colombia', 'Israel', 'Romania', 'Vietnam', 'Slovenia', 'Trinidad And Tobago', 'Ukraine', \n",
" 'American Samoa',\n",
" 'Costa Rica', 'Slovakia', 'Lithuania', 'Latvia', 'Philippines', 'Guatemala', 'Puerto Rico', 'Croatia', \n",
" 'Peru', 'Serbia',\n",
" 'Bangladesh', 'Venezuela', 'Bulgaria', 'Tunisia', 'Belarus', 'Dominican Republic', 'Uruguay', \n",
" 'Brunei', 'Luxembourg',\n",
" 'Egypt', 'Estonia', 'Iceland', 'Paraguay', 'Malta', 'Iraq', 'Bosnia And Herzegovina', 'Armenia', 'Mauritius', \n",
" 'Morocco',\n",
" 'Kyrgyzstan', 'Kazakhstan', 'Bouvet Island', 'Jamaica', 'Botswana', 'Ecuador', 'British Virgin Islands', \n",
" 'Pakistan',\n",
" 'Congo', 'Iran', 'Jordan']\n",
"# 'UK', \n",
"\n",
"locations = []\n",
"\n",
"geolocator = Bing(\"AqbMqgChvhrcKHPnavY2dmbyTP9L7XQG1iKCnZ61KXFOwcZbMABDNlyNnFnYGJvY\")\n",
"for i in countries:\n",
" print i\n",
" geocode = geolocator.geocode(i)\n",
" locations.append([i, geocode[1][0], geocode[1][1]])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 91 entries, 0 to 90\n",
"Data columns (total 3 columns):\n",
"country 91 non-null object\n",
"latitude 91 non-null object\n",
"longitude 91 non-null object\n",
"dtypes: object(3)\n",
"memory usage: 2.2+ KB\n",
"None\n",
"\n",
"=======\n",
" country latitude longitude\n",
"0 United States of America 39.4432563782 -98.9573364258\n",
"1 England 52.5988769531 -1.46688139439\n",
"2 Australia -25.5852413177 134.504119873\n",
"3 Canada 62.8329086304 -95.9133224487\n",
"4 Germany 51.2024650574 10.3822031021\n",
"5 Spain 40.3960266113 -3.55069255829\n",
"6 France 46.6372795105 2.33826231956\n",
"7 Italy 42.7669792175 12.4938230515\n",
"8 Ireland 53.1827278137 -8.19610214233\n",
"\n",
"=======\n",
" country latitude longitude\n",
"82 Bouvet Island -54.4342041016 3.41025114059\n",
"83 Jamaica 18.1434440613 -77.3465499878\n",
"84 Botswana -22.1867523193 23.8149414062\n",
"85 Ecuador -1.42152893543 -78.8710403442\n",
"86 British Virgin Islands 18.4430713654 -64.5713043213\n",
"87 Pakistan 29.9232196808 69.3577423096\n",
"88 Congo -2.8798661232 23.6563777924\n",
"89 Iran 32.5007781982 54.2942008972\n",
"90 Jordan 31.275762558 36.8283882141\n"
]
}
],
"source": [
"locations = np.array(locations)\n",
"locations = pd.DataFrame(locations, columns=['country','latitude','longitude'])\n",
"print locations.info()\n",
"print '\\n======='\n",
"print locations.head(9)\n",
"print '\\n======='\n",
"print locations.tail(9)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import cPickle\n",
"f = open('locations.save', 'wb')\n",
"cPickle.dump(locations,f)\n",
"f.close()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = open('locations.save', 'rb')\n",
"locations = cPickle.load(f)\n",
"f.close()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>country</th>\n",
" <th>latitude</th>\n",
" <th>longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>United States of America</td>\n",
" <td>39.4432563782</td>\n",
" <td>-98.9573364258</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>England</td>\n",
" <td>52.5988769531</td>\n",
" <td>-1.46688139439</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" country latitude longitude\n",
"0 United States of America 39.4432563782 -98.9573364258\n",
"1 England 52.5988769531 -1.46688139439"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"locations.head(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [Root]",
"language": "python",
"name": "Python [Root]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment