<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 time
import os
import csv

# Import API key
from api_keys import g_key
from api_keys import weather_api_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_list = pd.read_csv("..\output_data\cities.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 with API key // gkey not working? 
gmaps.configure(api_key=g_key)
locations = cities_list[["Lat", "Lng"]].astype(float)
humidity = cities_list["Humidity"].astype(float)
heatmap_humidity = gmaps.heatmap_layer(locations, weights=humidity, 
                                 dissipating=False, max_intensity=100,
                                 point_radius = 1)

# Create a combined map 
fig = gmaps.figure()
fig.add_layer(heatmap_humidity)


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># Fitting weather criteria is no hotter than 70 degrees fahrenheit and low humidity 
vacation_spots = cities_list.loc[(cities_list["Max Temp"] < 70) & (cities_list["Humidity"] < 30), :]
vacation_spots<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># Store into variable named hotel_df.
hotel_df = pd.DataFrame(vacation_spots)

# Add a "Hotel Name" column to the DataFrame.
hotel_df["Hotel Name"] = ""

hotel_df
# params dictionary to update each iteration
target_radius = 5000  
target_type = "Business"
target_search = "hotels" #terms?


# set up a parameters dictionary
params = {
    "radius": target_radius,
    "types": target_type,
    "keyword": target_search,
    "key": g_key
}

# loop through df, make an API call, according to parameters
for index, row in hotel_df.iterrows():
        # get lat, lng from df
        lat = row["Lat"]
        lng = row["Lng"]
        city = row["City"]
        # change location each iteration while leaving original params in place
        params["location"] = f"{lat},{lng}"
        print(f"Hotel found in {city}")
        base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
        hotel_list = requests.get(base_url, params=params)
        # convert to json
        hotels = hotel_list.json()
        
        # If there is an error tell us no hotel found and continue
        try: 
              hotel_name = hotel_df.loc[index, "Hotel Name"] = hotels["results"][0]["name"]
              print(f"{hotel_name} is the nearest hotel in {city}.")
              print()
        
        except: 
              print(f"No hotel found near {city}.")
              print()

hotel_df # with hotels added
# 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"]]
marker_layer = gmaps.marker_layer(locations, info_box_content=hotel_info)
fig = gmaps.figure()
fig.add_layer(marker_layer)
fig
# combine layers
fig = gmaps.figure()

fig.add_layer(heatmap_humidity)
fig.add_layer(marker_layer)

fig
# Analysis 

# There is a correlation between max temp & latitude in the southern hemisphere

# There is negative correlation between max temp & latitude in the northern hemisphere

# There is no city with humidity above 100<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09661728940968384, 'fraction_numerical': 0.004864028299801017, 'mean_word_length': 3.9768976897689767, 'pattern_counts': {'":': 4, '<': 37, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '580617', 'license': 'ADSL', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1361, 'n_words': 466, 'path': 'starter_code/Carter_VacationPy.ipynb', 'repo_name': 'computercavemen/python-api-challenge', 'size': '4523'}