<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
import json
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>cities_df = pd.read_csv('../cities.csv')
cities_df = cities_df.drop(['Unnamed: 0'], axis=1)
cities_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)

locations = cities_df[["latitude", "longitude"]]
humidity = cities_df["humidity"]
humidity
fig = gmaps.figure()
heat_layer = gmaps.heatmap_layer(locations, weights=humidity,dissipating=False,max_intensity=100,point_radius=1)
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>hotel_df = cities_df.loc[(cities_df['max temperature']<80) & (cities_df['max temperature']>70) & (cities_df['wind speed']<10) & (cities_df['cloudiness']==0)]
hotel_df<jupyter_output><empty_output><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>hotel_df['Hotel Name'] = ""
target_radius = 5000
target_search = "Hotel"

base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
params = {
    "radius": target_radius,
    "keyword": target_search,
    "key": g_key
}

for index, row in hotel_df.iterrows():

    lat = row['latitude']
    lon = row['longitude']

    params['location'] = f"{lat},{lon}"

    print(f"Retrieving Results for Index {index}.")
    response = requests.get(base_url, params=params).json()
    
    results = response['results']
    
    try:
        print(f"Closest hotel is {results[0]['name']}.")
        print("------------")

        hotel_df.loc[index, 'Hotel Name'] = results[0]['name']

    except (KeyError, IndexError):
        print("No hotel within 5000 meters")
        hotel_df.loc[index, 'Hotel Name'] = "No hotel within 5000 meters"
        print("------------")
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[["latitude", "longitude"]]
humidity = hotel_df["humidity"]
# Add marker layer ontop of heat map
fig = gmaps.figure()
marker_layer = gmaps.marker_layer(locations, info_box_content=hotel_info)
heat_layer = gmaps.heatmap_layer(locations, weights=humidity,dissipating=False,max_intensity=80,point_radius=3)
fig.add_layer(heat_layer)
fig.add_layer(marker_layer)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12489818083084442, 'fraction_numerical': 0.009231604670105892, 'mean_word_length': 5.26530612244898, 'pattern_counts': {'":': 3, '<': 37, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '275050', 'license': 'ADSL', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1184, 'n_words': 342, 'path': 'VacationPy/.ipynb_checkpoints/VacationPy-checkpoint.ipynb', 'repo_name': 'SamClements94/API-Challenge', 'size': '3683'}