shhudspeth / lahman-baltimoreparks Goto Github PK
View Code? Open in Web Editor NEWPracticing with Geocoder and Bokeh using data from Lahman's baseball datasets
Practicing with Geocoder and Bokeh using data from Lahman's baseball datasets
If you look at your data in the geo_park
dataframe you'll see that you sometimes get an over query limit. That's because your app is making too many calls too quickly. You're data set is small so even if we just add in a delay it won't take too long.
To do that, I think you have no choice but to remove the nice list comprehension geo_code = [geocoder.google(geo_parks['address'][x]) for x in range(len(geo_parks['address'])) ]
and replace it with:
[Note: This piece of code has been edited]
import time
geo_codes = []
for address in geo_parks['address']:
geo_code = geocoder.google(address)
if str(geo_code) == '<[OVER_QUERY_LIMIT] Google - Geocode [empty]>':
print(address, geo_code)
time.sleep(5)
geo_code = geocoder.google(address)
geo_codes.append(geo_code)
geo_parks['geo_code']= geo_codes
geo_parks
I also modified the for loop to use the address itself rather than a numerical indexer. In the code you had it would look like this:
geo_code = [geocoder.google(x) for x in geo_parks['address'] ]
I tried loading the html file to view the maps and I ended up getting the Expired Key Map Error
https://developers.google.com/maps/documentation/javascript/error-messages#expired-key-map-error
(Just an FYI.)
You might have generated a new API token at some point after which might be part of it.
You can fix the copy warnings you're getting by specifically setting the values as copies rather than referencing the dataframe objects.
For example:
geo_parks['long'][4] = geo_parks['long'][5].copy()
geo_parks['long'][8] = geo_parks['long'][7].copy()
geo_parks['long'][6] = geocoder.google("324 E 25th St Baltimore MD").lng
Also, one of the beauties of using an Jupyter notebook is that you don't need to print your dataframes. Just calling it as the final command in the cell with show it and leave it in a nicer format.
Edit:
I was thinking of a different error when I told you the above improvement. It should actually be:
geo_parks.loc[4,'long'] = geo_parks['long'][5]
geo_parks.loc[8,'long'] = geo_parks['long'][7]
geo_parks.loc[6,'long'] = geocoder.google("324 E 25th St Baltimore MD").lng
geo_parks.head()
Am I correct in assuming that the reason you're using Google Maps API is to fill in the missing data?
If so I would recommend filling it this way, so that you don't need to do it by hand.
for i,b in enumerate(geo_parks.lat.isna()):
if b == True:
geo_parks.loc[i,'lat'] = geo_parks.loc[i, 'geo_code'].lat
for i,b in enumerate(geo_parks.long.isna()):
if b == True:
geo_parks.loc[i,'long'] = geo_parks.loc[i, 'geo_code'].lng
enumerate()
zips a list with it's index into a tuple. I use i
to indicate index and b
to indicate boolean.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.