<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 json
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>#import "clean cities csv"
file = "../output_data/clean_cities_data.csv"
weather_df = pd.read_csv(file)
weather_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>#access maps with unique API key
gmaps.configure(api_key = g_key)
#create coordinates
records = weather_df[["Latitude", "Longitude"]].to_records(index=False)
coordinates = list(records)
weights = weather_df['Humidity']
#customize map
figure_layout = {'width': '500px', 'margin': '0 auto 0 auto'}
fig = gmaps.figure(layout=figure_layout)
heat_layer = gmaps.heatmap_layer(coordinates, weights = weights)

#assign marker layer
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>#drop null values
vacation_df = weather_df.dropna(axis=0)
vacation_df
#select only ideal cities
#Criteria - Temperature >70 <85 degrees, cloudiness <50, humidity <60

ideal_cities_df = vacation_df.loc[(vacation_df["Temperature"] >=75) & 
                                  (vacation_df["Temperature"] <=80) & 
                                  (vacation_df["Cloudiness"] <50) & 
                                  (vacation_df["Humidity"] <50)]
ideal_cities_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
hotel_df = ideal_cities_df.filter(["City Name", "Country Name", "Latitude", "Longitude"], axis=1)
#rename column headers to match requirements below for map
hotel_df.rename(columns={'City Name':'City',
                         'Country Name': 'Country',
                          'Latitude':'Lat',
                          'Longitude':'Lng'},inplace=True)
hotel_df["Hotel Name"] = ""
hotel_df

#query from Google Places API
base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

#loop through coordinates to get responses
for index,row in hotel_df.iterrows():

    
    #get location from df
    latitude = row["Lat"]
    longitude = row["Lng"]
    city = row["City"]
    
    #add to params
    locations = f"{latitude},{longitude}"
    
    #set up params
    params = {"location":locations,
               "keyword": "lodging",
                "radius":5000, 
                #"rankby":"distance",
                   "key": g_key,}
    
    #create URL for request
    response = requests.get(base_url, params=params).json()
    
    #extract results - print for testing
    #print(json.dumps(response, indent=4, sort_keys=True))
    
    #in case there are errors
    try:
        print("------------------------------------")
        print(f' Hotel found within 5000m of {city}')
        print("------------------------------------")
        hotel_df.loc[index, "Hotel Name"] = response["results"][0]["name"]
        
    except (KeyError, IndexError):
        print("------------------------------------")
        print("Not result found... skipping.")
        print("------------------------------------")
        hotel_df.loc[index, "Hotel Name"] = "N/A"
        

    
#drop any with N/A value
#hotel_df = hotel_df[hotel_df["Hotel Name"] != "N/A"]
#view hotel names on df
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_layer = gmaps.marker_layer(
    locations,
    info_box_content=hotel_info,
    display_info_box=True)

# Add layer
fig.add_layer(marker_layer)

#update figure display
#gmaps.figure( zoom_level=16, center=(36.0999,80.2442)) #coordinates are for <NAME>, NC. I wanted to default the zoom if I could.

# Display the map
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1391845752159068, 'fraction_numerical': 0.010243020686884917, 'mean_word_length': 3.2527754056362084, 'pattern_counts': {'":': 5, '<': 42, '<?xml version=': 0, '>': 38, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '499251', 'license': 'ADSL', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1497, 'n_words': 460, 'path': 'starter_code/VacationPy_APT.ipynb', 'repo_name': 'taftap8/python_api_challenge', 'size': '4986'}