<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. Task:1. Get the city data from the .csv file created in the last exercise.2. Generate a Humidity heat map based on the city data from the above step3. Filter out a small set of cities that will fit a criterion based on temp, wind speed and cloudiness4. Get the nearest hotel for these cities5. plot these cities on the heat map with location markers.<jupyter_code>import warnings
warnings.filterwarnings('ignore')
# 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># Load the CSV file as DataFrame
csv_file = os.path.join('.', 'output_data', 'cities.csv')
cities_df = pd.read_csv(csv_file, index_col=False)
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># Create a Heatmap layer based on Humidity level

#Get the gmaps api key
gmaps.configure(api_key=g_key)

# Get the Humidity level of the each City location along with the Latitude and Longitude
humidity_weight = cities_df["Humidity"].astype(
    float)  # Store Humidity as weights
locations_df = cities_df[["Lat", "Lng"]].astype(
    float)  # Store 'Lat' and 'Lng' into locations DataFrame

# Values to control the size of the figure
figure_layout = {
    'width': '400px',
    'height': '600px',
    'border': '1px solid black',
    'padding': '1px'
}

# Create the gmaps figure with zoom level
fig = gmaps.figure(figure_layout, center=(20, 10), zoom_level=2)

# Create the Heat Layer for Humidity
heat_layer = gmaps.heatmap_layer(locations_df,
                                 weights=humidity_weight,
                                 dissipating=False,
                                 max_intensity=100,
                                 point_radius=1.5)

# Add the Heat Layer to the figure
fig.add_layer(heat_layer)

# Display the world map with the Humidity Heat layer of the cities globally
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># Narrow down the DataFrame to find your ideal weather condition.
# 1. Temperature greater than 70 °F
# 2. Wind speed less than 10 mph.
# 3. Cloudiness less than 3 %

hotel_df = cities_df[(cities_df['Max Temp'] > 70)
                     & (cities_df['Wind Speed'] < 10)
                     & (cities_df['Cloudiness'] < 3)]
# Dislpay the Hotel DataFrame based on the above filter Criterion
hotel_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>base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

for index, row in hotel_df.iterrows():
    row_lat = row["Lat"]
    row_lng = row["Lng"]

    # Set the parameters for the web api call
    parameters = {
        "key": g_key  # API Key
        ,"type": "lodging"  # Location Type
        ,"radius": 5000  # Target radius of 5,000 meters
        ,"location":f'{row_lat}, {row_lng}'  # Geographical Coordinates for the location
        ,"rankBy": "distance"  # Rank by distance
    }

    #Call the API and get the response
    response = requests.get(base_url, params=parameters)

    #Get the JSON from the response
    json_response = response.json()

    try:
        hotel_df.loc[index, "Hotel Name"] = json_response["results"][0]["name"]
        hotel_df.loc[index, "Hotel Location"] = json_response["results"][0]["plus_code"]["compound_code"]
        hotel_df.loc[index, "Hotel Lng"] = json_response["results"][0]["geometry"]["location"]["lng"]
        hotel_df.loc[index, "Hotel Lat"] = json_response["results"][0]["geometry"]["location"]["lat"]
    except:
        print(f"\n[Warning] Hotel found not found in the vicinity of {index}:{row['City']}, {row['Country']} >>>> Skipping.\n"
        )

    print(json.dumps(json_response, indent=4))
hotel_df
hotel_df.fillna('', inplace=True)
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"]]

#Create the market layer to be able to plot the markers on the map
marker_layer = gmaps.marker_layer(locations, info_box_content=hotel_info)
# Add marker layer on top of heat map generated earlier
fig.add_layer(marker_layer)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10316420146040067, 'fraction_numerical': 0.009923235349185546, 'mean_word_length': 3.97856477166822, 'pattern_counts': {'":': 5, '<': 37, '<?xml version=': 0, '>': 40, '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': '130193', 'license': 'ADSL', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1626, 'n_words': 577, 'path': 'VacationPy.ipynb', 'repo_name': 'sanjive/BCS_06_PythonAPI-Challenge', 'size': '5341'}