<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>pip install citipy
# 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>#Important weather data CSV file from Weather Py
weather_data = pd.read_csv("cities.csv")
weather_data_df = weather_data
weather_data_df.head()
#Find the number of nan values
weather_data_df.info()
#Modify weather_data to remove the nan values
weather_data_df=weather_data_df[~weather_data_df['Country'].isna()]
#Confirm the same amount of rows in each column and nan values have been dropped
weather_data_df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 544 entries, 0 to 547
Data columns (total 10 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   City_ID     544 non-null    int64  
 1   City        544 non-null    object 
 2   Cloudiness  544 non-null    int64  
 3   Country     544 non-null    object 
 4   Date        544 non-null    int64  
 5   Humidity    544 non-null    int64  
 6   Lat         544 non-null    float64
 7   Lng         544 non-null    float64
 8   Max Temp    544 non-null    float64
 9   Wind Speed  544 non-null    float64
dtypes: float64(4), int64(4), object(2)
memory usage: 46.8+ KB<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 g-maps
gmaps.configure(api_key=g_key)
#create a dataframes for countries
countries = list(weather_data_df["Country"].unique())
countries
#Use the Lat and Lng as locations and Humidity as the weight.
countries = weather_data_df[["Lat", "Lng"]]
humidity = weather_data_df["Humidity"]
fig = gmaps.figure()
heatmap_layer = gmaps.heatmap_layer(countries, weights=humidity,
                                   dissipating=False, max_intensity=5,
                                   point_radius=1)
fig.add_layer(heatmap_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>#create new dataframe
new_df = pd.DataFrame(weather_data_df, columns = ["City", "Max Temp", "Wind Speed", "Cloudiness"])
max_temp = (new_df["Max Temp"] <= 80) & (new_df["Max Temp"] > 70)
wind_speed = new_df["Wind Speed"] < 10
cloudiness = new_df["Cloudiness"] == 0
new_df[max_temp& wind_speed & cloudiness]
new_df.info()
# Find the nan values
weather_data_df[weather_data_df['Country'].isna()]<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>hotel_df = pd.DataFrame(weather_data_df, columns=["City", "Country", "Lat", "Lng"])
hotel_df["Hotel Name"] = ""
hotel_df
#Set parameters to search for hotels with 5000 meters
#Hit the Google Places API for each city's coordinates
target_coordinates = f"{hotel_df['Lat'][0]},{hotel_df['Lng'][0]}"
target_search = "hotel"
target_radius = 5000
target_type = "hotel"
params = {
    "location": target_coordinates,
    "keyword": target_search,
    "radius": target_radius,
    "type": target_type,
    "key": g_key
}
base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
# 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
# Add marker layer ontop of heat map
markers = gmaps.marker_layer(locations)
fig.add_layer(markers)
# Display figure
fig<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup