<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

import json<jupyter_output><empty_output><jupyter_text>Store Part I results into DataFrame* Load the csv exported in Part I to a DataFrame<jupyter_code># File to Load (Remember to Change These)
weather = "output_data/WeatherData.csv"

# Read School and Student Data File and store into Pandas DataFrames
df_weather = pd.read_csv(weather)

df_weather
df_weather = df_weather.rename(columns={'Latitude_x': 'Latitude'})
df_weather = df_weather.drop(columns=['Latitude_y'])
df_weather.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># Configure gmaps with API key
gmaps.configure(api_key=g_key)
# Store 'Lat' and 'Lng' into  locations 
locations = df_weather[["Latitude", "Long"]].astype(float)

# Convert Poverty Rate to float and store
# HINT: be sure to handle NaN values
df_weather = df_weather.dropna()
humi = df_weather["Humidity"].astype(float)
# Create a poverty Heatmap layer
fig = gmaps.figure()

heat_layer = gmaps.heatmap_layer(locations, weights=humi, 
                                 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>df_weather
df_weathercriteria = df_weather.loc[(df_weather['Cloudiness']==0) & 
                                    (df_weather['WindSpeed'] < 10.0)&
                                    (df_weather['Temp'] <80.0) &
                                    (df_weather['Temp'] > 70.0) ]

df_weathercriteria<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>narrowed_city_df = df_weathercriteria
narrowed_city_df["Hotel Name"] = ""
narrowed_city_df
#TEST

# params dictionary to update each iteration
#params2 = {
 #   "radius": 5000,
 #   "types": "lodging",
 #   "location": "31.05,76.12",
 #   "key": g_key
#}

#base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

#testrequest = requests.get(base_url, params= params2)
#print(testrequest.json())
#print(json.dumps(testrequest.json(),indent=2))
#testrequest.json()["results"][0]["name"]
#hotelname = testrequest.json()["results"][0]["name"]
# params dictionary to update each iteration
params = {
    "radius": 5000,
    "types": "lodging",
    "location": "location",
    "key": g_key
}

# Use the lat/lng we recovered to identify airports
for index, row in narrowed_city_df.iterrows():
    lat = row["Latitude"]
    lng = row["Long"]

    # change location each iteration while leaving original params in place
    params["location"] = f"{lat},{lng}" #<=> "31.05,76.12"

    # Use the search term: "International Airport" and our lat/lng
    base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

    # make request and print url
    name_address = requests.get(base_url, params=params)
    
    #print the name_address url, avoid doing for public github repos in order to avoid exposing key
    #print(name_address.url)

    # convert to json
    name_address = name_address.json()
    # print(json.dumps(name_address, indent=4, sort_keys=True))

    # Since some data may be missing we incorporate a try-except to skip any that are missing a data point.
    try:
        narrowed_city_df.loc[index, "Hotel Name"] = name_address["results"][0]["name"]

    except (KeyError, IndexError):
        print("Missing field/result... skipping.")
narrowed_city_df
# Store 'Lat' and 'Lng' into  locations 
locations = narrowed_city_df[["Latitude", "Long"]].astype(float)

# Convert Poverty Rate to float and store
# HINT: be sure to handle NaN values
#df_weather = df_weather.dropna()
humi2 = narrowed_city_df["Humidity"].astype(float)
# Create a poverty Heatmap layer
fig = gmaps.figure()

heat_layer = gmaps.heatmap_layer(locations, weights=humi2, 
                                 dissipating=False, max_intensity=100,
                                 point_radius = 1)

fig.add_layer(heat_layer)

fig
narrowed_city_df
hotel_df = narrowed_city_df[["Hotel Name","CityName", "Country","Latitude","Long"]]
#hotel_df.dtypes
 # 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>{CityName}</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 narrowed_city_df.iterrows()]
locations = hotel_df[["Latitude", "Long"]]

# Add marker layer ontop of heat map


marker_layer = gmaps.marker_layer(locations, info_box_content=hotel_info)
fig = gmaps.figure()
fig.add_layer(marker_layer)
#fig

fig.add_layer(heat_layer)
# Display Map
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11254874158099964, 'fraction_numerical': 0.009748316199929103, 'mean_word_length': 4.220166512488436, 'pattern_counts': {'":': 8, '<': 38, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '369779', 'license': 'ADSL', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1778, 'n_words': 515, 'path': 'WeatherPy/.ipynb_checkpoints/VacationPy-checkpoint.ipynb', 'repo_name': 'vrclaros/python-api-challenge', 'size': '5642'}