Giter Site home page Giter Site logo

lahman-baltimoreparks's Introduction

Lahman-BaltimoreParks

Practicing with Geocoder and Bokeh using data from Lahman's baseball datasets

lahman-baltimoreparks's People

Contributors

shhudspeth avatar

Stargazers

Lauren avatar

Watchers

James Cloos avatar

lahman-baltimoreparks's Issues

Copy Warnings

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()

Filling in Missing Data

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.

Fixing the Over Query Limit

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'] ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.