<jupyter_start><jupyter_text>VacationPy---- Note* 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 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>output_data_file = "../output_data/weather_data.csv"
weather_data_df = pd.read_csv(output_data_file)
weather_data_df
# weather_data = pd.read_csv("weather_data.csv") 
# weather_data.head()
# weather_data.read_csv("../output_data/weather_data.csv")<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># configure gmaps
gmaps.configure(api_key=g_key)

# Plot Heatmap
locations = weather_data_df[["Lat", "Lng"]]
humidity = weather_data_df["Humidity"].astype(float)

# Create heat layer
fig = gmaps.figure()
heat_layer = gmaps.heatmap_layer(locations, weights=humidity, 
                                 dissipating=False, max_intensity=np.max(humidity),
                                 point_radius=4)


# Add layer
fig.add_layer(heat_layer)

# Display figure
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.
# Drop any rows that don't contain all three conditions. You want to be sure the weather is ideal.

weather_conditions_df = weather_data_df.loc[(weather_data_df["Max Temp"] > 70) & (weather_data_df["Max Temp"] < 80) &
                                           (weather_data_df["Cloudiness"] == 0) & (weather_data_df["Wind Speed"] < 10)]
weather_conditions_df = weather_conditions_df.dropna(how='any')
weather_conditions_df.reset_index(inplace=True)
del weather_conditions_df['index']
weather_conditions_df
# A max temperature lower than 80 degrees but higher than 70.
# Wind speed less than 10 mph.
# Zero cloudiness.
# Drop any rows that don't contain all three conditions. You want to be sure the weather is ideal.
# weather_conditions_df = pd.DataFrame(weather_data_df, columns = ["Cloudiness", "Humidity", "Max Temp", "Wind Speed"])
# weather_max_temp = (weather_conditions_df["Max Temp"] <= 80) & (weather_conditions_df["Max Temp"] >= 70)
# weather_wind_speed = weather_conditions_df["Wind Speed"] < 10
# weather_cloudiness = weather_conditions_df["Cloudiness"] == 0

# Storing variables
# weather_clean_df = weather_conditions_df[weather_max_temp & weather_wind_speed & weather_cloudiness]
# weather_clean_df = weather_conditions_df.dropna()
# weather_clean_df.reset_index(inplace=True)
# del weather_clean_df['index']
# weather_clean_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># Create hotel_df dataframe
hotel_df = weather_conditions_df.loc[:,["City", "Country", "Lat", "Lng"]]

# Add hotel name column
hotel_df["Hotel Name"] = ""
hotel_df
# Create open list
hotel_name = []

target_coordinates = f"{hotel_df['Lat'][0]},{hotel_df['Lng'][0]}"
target_search = "hotel"
target_radius = 5000
target_type = "hotel"

params = {"location": target_coordinates,
          "type": target_type,
          "keyword": target_search,
          "radius": target_radius,
          "key": "g_key"}


for index, row in hotel_df.iterrows():
    lat = row['Lat']
    lng = row['Lng']
    city_name = row['City']
    
    # Set Parameters
    params["location"] = f"{lat},{lng}"
    
    base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
    
    # Print Results
    print(f"Retrieving Results for Index {index}: {city_name}.")
    response = requests.get(base_url, params=params).json()
 
    # Get Results
    response['results']
    
    # Find closest hotel and store in dataframe
    try:
        print(f"The Closest hotel in {city_name} is {results[0]['name']}.")
        hotel_name.append(results[results][0]['name'])
    
    # If there isn't a hotel, report missing
    except(KeyError, IndexError):
        print("Missing field/result... skipping.")
# 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
markers = gmaps.marker_layer(locations)
fig.add_layer(markers)

# Display figure
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1125590179414542, 'fraction_numerical': 0.0073654390934844195, 'mean_word_length': 4.670235546038544, 'pattern_counts': {'":': 5, '<': 39, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '181776', 'license': 'ADSL', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1649, 'n_words': 480, 'path': 'starter_code/VacationPy.ipynb', 'repo_name': 'keggert/python-api-challenge', 'size': '5295'}