<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

from config 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>csv_path="cities.csv"
cities_df=pd.read_csv(csv_path)
cities_df.head()<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[["Lat", "Lng"]]
humidity = cities_df["Humidity (%)"]
figure_layout = {
    'width': "100%",
    'height': '400px',
    'padding': '1px',}

fig = gmaps.figure(layout=figure_layout, center=(20.0, 5.0), zoom_level=1.9)
heatmap_layer = gmaps.heatmap_layer(locations, weights=humidity, dissipating=False)
fig.add_layer(heatmap_layer)
heatmap_layer.max_intensity = max(weights)
heatmap_layer.point_radius = 3
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>#Criteria: Temp between 70-80(f), wind<10(%),Cloud==0,
ideal_cities = cities_df.loc[(cities_df["Max Temp (F)"] > 70) & 
                               (cities_df["Max Temp (F)"] < 80) & 
                               (cities_df["Wind Speed (mph)"] < 10) & 
                               (cities_df["Cloudiness (%)"] == 0), :].reset_index(drop=True).dropna()
ideal_cities<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 = ideal_cities[["City", "Country", "Lat", "Lng"]].copy()
hotel_df["Hotel Name"] = np.nan
hotel_df
target_search = "hotel"
target_radius = 5000
target_type = "lodging"

params = { "keyword": target_search,
            "radius": target_radius,
            "type": target_type,
            "key": g_key}
#URL
base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
for index, row in hotel_df.iterrows():
    
    # --- get the coordinates and store in params dictionary ---
    lat = row["Lat"]
    lng = row["Lng"]
    params["location"] = f"{lat},{lng}"
    
    # --- call the API and get hotel details for each city ---
    hotel_data = requests.get(base_url, params).json()
    
    # --- use exception handling to save the first hotel name for each city ---
    
    try:
        hotel_name = hotel_data["results"][0]["name"]
        hotel_df.loc[index, "Hotel Name"] = hotel_name
        print(f"City: {row['City']}. Nearest hotel: {hotel_name}")
              
    except:
        print(f"Could not find information for city '{row['City']}'")    
hotel_df.dropna(how="any",inplace=True)
hotel_df.reset_index(drop=True, inplace=True)

#display final dataframe ---
hotel_df
info_box_template = """
<dl>
<dt>Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
</dl>
"""

hotel_info = [info_box_template.format(**row) for index, row in hotel_df.iterrows()]
locations = hotel_df[["Lat", "Lng"]]
markers = gmaps.marker_layer(locations, info_box_content = hotel_info)
fig.add_layer(markers)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13149768399382397, 'fraction_numerical': 0.00977869274318065, 'mean_word_length': 4.224462365591398, 'pattern_counts': {'":': 4, '<': 38, '<?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': '528602', 'license': 'ADSL', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1270, 'n_words': 345, 'path': 'Analysis/VacationPy .ipynb', 'repo_name': 'LaurenPrins/python-api-challenge', 'size': '3886'}