<jupyter_start><jupyter_text>VacationPy---- Note* Keep an eye on your API usage. Use https://developers.google.com/maps/reporting/gmp-reporting as reference for how to monitor your usage and billing.* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import gmaps
import os
from pprint import pprint
# Import API key
from api_keys import g_key<jupyter_output><empty_output><jupyter_text>Store Part I results into DataFrame* Load the csv exported in Part I to a DataFrame<jupyter_code>#Saves random cities csv data to new data frame
gmap_df = pd.read_csv('random_cities.csv')
gmap_df<jupyter_output><empty_output><jupyter_text>Humidity Heatmap* Configure gmaps.* Use the Lat and Lng as locations and Humidity as the weight.* Add Heatmap layer to map.<jupyter_code>gmaps.configure(api_key=g_key) #Load API key

#Establish Lat and Lng columns as coordinates
locations = gmap_df[['Lat','Lng']]
#Establish Humidity column with float values
humidity = gmap_df['Humidity'].astype(float)

#Set figure layout
figure_layout = {
    'width': '500px',
    'height': '500px',
    'border': '1px solid black',
    'padding': '1px',
    'margin': '0 auto 0 auto'
}
#Applies figure layout to figure
fig = gmaps.figure(layout=figure_layout)
#Creates heat layer and adds it to figure
heat_layer = gmaps.heatmap_layer(locations,weights=humidity,dissipating=True,
                                 max_intensity=40,point_radius=7)
fig.add_layer(heat_layer)
fig<jupyter_output><empty_output><jupyter_text>Create new DataFrame fitting weather criteria* Narrow down the cities to fit weather conditions.* Drop any rows will null values.<jupyter_code>#A max temperature lower than 80 degrees but higher than 70.
#Wind speed less than 10 mph.
#Zero cloudiness.
gmap_df_2 = gmap_df.drop(gmap_df[(gmap_df['Max Temp']<70) | (gmap_df['Max Temp']>80)].index)
gmap_df_2 = gmap_df_2.drop(gmap_df_2[(gmap_df_2['Wind Speed'] >= 10)].index)
gmap_df_2 = gmap_df_2.drop(gmap_df_2[(gmap_df['Cloudiness'] != 0)].index)
#for i, city in gmap_df_2.iterrows():
#    try:
#        if (city[i,'Max Temp'] < 70 | city[i,'Max Temp'] > 80) & (city[i,'Wind Speed'] >= 10) & (city[i,'Cloudiness'] != 0):
#            city = []
#    except:
#        print('Data not available')
gmap_df_2<jupyter_output><ipython-input-25-53c02069cda3>:6: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  gmap_df_2 = gmap_df_2.drop(gmap_df_2[(gmap_df['Cloudiness'] != 0)].index)<jupyter_text>Hotel Map* Store into variable named `hotel_df`.* Add a "Hotel Name" column to the DataFrame.* Set parameters to search for hotels with 5000 meters.* Hit the Google Places API for each city's coordinates.* Store the first Hotel result into the DataFrame.* Plot markers on top of the heatmap.<jupyter_code>#Create hotel_df and create new column Hotel Name
hotel_df = gmap_df_2
hotel_df['Hotel Name'] = ''

#Base url and preliminary parameters for API call
base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
params = {'type':'lodging','radius':5000,'key':g_key}

#Establishes for loop for lat/lng conversion and API calls
for i,row in hotel_df.iterrows():
    #Store Lat and Lng and insert into new dictionary key
    #called 'location'
    lat = row['Lat']
    lng = row['Lng']
    params['location'] = f'{lat},{lng}'
    #API request
    response = requests.get(base_url,params=params).json()
    try:
        #Tries to store first hotel name from response in
        #Hotel Name column
        hotel_df.loc[i, 'Hotel Name'] = response['results'][0]['name']
    except:
        #Puts 'No hotel found' if hotel not found
        hotel_df.loc[i, 'Hotel Name'] = 'No hotel found'
hotel_df
# NOTE: Do not change any of the code in this cell

# Using the template add the hotel marks to the heatmap
info_box_template = """
<dl>
<dt>Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
</dl>
"""
# Store the DataFrame Row
# NOTE: be sure to update with your DataFrame name
hotel_info = [info_box_template.format(**row) for index, row in hotel_df.iterrows()]
locations = hotel_df[["Lat", "Lng"]]
# Add marker layer ontop of heat map
marker = gmaps.marker_layer(locations,info_box_content=hotel_info)
fig.add_layer(marker)
# Display figure
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11520532741398447, 'fraction_numerical': 0.01509433962264151, 'mean_word_length': 4.844357976653696, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '539848', 'license': 'ADSL', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1485, 'n_words': 473, 'path': 'WeatherPy/VacationPy_PPhilip.ipynb', 'repo_name': 'pramodphilip/python-api-challenge', 'size': '4505'}