Ejemplo n.º 1
0
# development, research, and testing of the theories and programs        #
# to determine their effectiveness. The authors and publisher make       #
# no warranty of any kind, expressed or implied, with regard to these    #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or       #
# consequential damages in connection with, or arising out of, the       #
# furnishing, performance, or use of these programs.                     #
##########################################################################
# Section 15.2 Self Check snippets

# Exercise 1
import keys

from geopy import OpenMapQuest

geo = OpenMapQuest(api_key=keys.mapquest_key)

geo.geocode('Chicago, IL')

##########################################################################
# (C) Copyright 2019 by Deitel & Associates, Inc. and                    #
# Pearson Education, Inc. All Rights Reserved.                           #
#                                                                        #
# DISCLAIMER: The authors and publisher of this book have used their     #
# best efforts in preparing the book. These efforts include the          #
# development, research, and testing of the theories and programs        #
# to determine their effectiveness. The authors and publisher make       #
# no warranty of any kind, expressed or implied, with regard to these    #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or       #
# consequential damages in connection with, or arising out of, the       #
Ejemplo n.º 2
0
            "$search": senator
        }}))

# Show Tweet Counts for Each Senator
tweet_counts_df = senators_df.assign(Tweets=tweet_counts)

tweet_counts_df.sort_values(by='Tweets', ascending=False).head(10)

# Get the State Locations for Plotting Markers
from geopy import OpenMapQuest

import time

from state_codes import state_codes

geo = OpenMapQuest(api_key=keys.mapquest_key)

states = tweet_counts_df.State.unique()

states.sort()

locations = []

for state in states:
    processed = False
    delay = .1
    while not processed:
        try:
            locations.append(geo.geocode(state_codes[state] + ', USA'))
            print(locations[-1])
            processed = True