<jupyter_start><jupyter_text>Deliverable 2. Create a Customer Travel Destinations Map<jupyter_code># Dependencies and Setup
import pathlib
import sys

import gmaps
import pandas as pd
import requests

# Import API key
sys.path.append('..')
from config import g_key

# Configure gmaps API key
gmaps.configure(api_key=g_key)<jupyter_output><empty_output><jupyter_text>Import City and Weather Data<jupyter_code># 1. Import the WeatherPy_database.csv file. 
# keep_default_na is false to avoid changing the country code for Namibia from
# NA to NaN. The na_values list is used to provide some common NaN type values
# in case they exist in other columns of the csv.
city_data_df = pd.read_csv(
    pathlib.Path("../Weather_Database/WeatherPy_Database.csv"),
    na_values=['NULL', 'NaN', 'n/a', 'nan', 'null'],
    keep_default_na=False
)
city_data_df.head()<jupyter_output><empty_output><jupyter_text>Retrieve User Preferences<jupyter_code># 2. Prompt the user to enter minimum and maximum temperature criteria 
min_temp = float(input("What is the minimum temperature you would like for your trip? "))
max_temp = float(input("What is the maximum temperature you would like for your trip? "))<jupyter_output>What is the minimum temperature you would like for your trip?  75
What is the maximum temperature you would like for your trip?  90<jupyter_text>Apply User Preferences<jupyter_code># 3. Filter the city_data_df DataFrame using the input statements to create a 
# new DataFrame using the loc method.
preferred_cities_df = city_data_df.loc[(city_data_df['Max Temp'] >= min_temp)
                                       & (city_data_df['Max Temp'] <= max_temp)]
# 4a. Determine if there are any empty rows.
preferred_cities_df.count()
# 4b. Drop any empty rows and create a new DataFrame that doesn’t have empty
# rows.
preferred_cities_df = preferred_cities_df.dropna()
preferred_cities_df.count()<jupyter_output><empty_output><jupyter_text>Add Empty Hotel Column<jupyter_code># 5a. Create DataFrame called hotel_df to store hotel names along with city,
# country, max temp, and coordinates.
hotel_df = preferred_cities_df[["City", "Country", "Max Temp", 
                                "Current Description", "Lat", "Lng"]].copy()

# 5b. Create a new column "Hotel Name"
hotel_df["Hotel Name"] = ""
hotel_df.head(10)<jupyter_output><empty_output><jupyter_text>Retrieve Nearest Hotels<jupyter_code># 6a. Set parameters to search for hotels with 5000 meters.
params = {
    "radius": 5000,
    "type": "lodging",
    "key": g_key
}

# 6b. Iterate through the hotel DataFrame.
for index, row in hotel_df.iterrows():
    # 6c. Get latitude and longitude from DataFrame
    lat = row["Lat"]
    lng = row["Lng"]
    # Add the latitude and longitude to location key for the params dictionary.
    params["location"] = f"{lat},{lng}"

    # 6d. Set up the base URL for the Google Directions API to get JSON data.
    base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
    
    try:
    # 6e. Make request and retrieve the JSON data from the search.
        hotels = requests.get(base_url, params=params).json()
    # 6f. Get the first hotel from the results and store the name, if a hotel
    # isn't found skip the city.
        hotel_df.loc[index, "Hotel Name"] = hotels["results"][0]["name"]
    except (IndexError):
        print("Hotel not found... skipping")
print("-----------------------------")
print("Data Retrieval Complete      ")
print("-----------------------------")
# 7. Drop the rows where there is no Hotel Name.
clean_hotel_df = hotel_df.drop(index=hotel_df[hotel_df['Hotel Name'] == ''].index)<jupyter_output><empty_output><jupyter_text>Export Vacation Data<jupyter_code># 8a. Create the output File (CSV)
output_data_file = pathlib.Path("WeatherPy_Vacation.csv")
# 8b. Export the City_Data into a csv
clean_hotel_df.to_csv(output_data_file, index_label="City_ID")<jupyter_output><empty_output><jupyter_text>Create Marker Layer with Info Box<jupyter_code># 9. Using the template add city name, the country code, the weather description
# and maximum temperature for the city.
info_box_template = """
<dl>
<dt>Hotel Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
<dt>Current Weather</dt><dd>{Current Description} and {Max Temp} °F</dd>
</dl>
"""

# 10a. Get the data from each row and add it to the formatting template and
# store the data in a list.
hotel_info = [info_box_template.format(**row) for index, row in clean_hotel_df.iterrows()]

# 10b. Get the latitude and longitude from each row and store in a new
# DataFrame.
locations = clean_hotel_df[["Lat", "Lng"]]
# 11a. Add a marker layer for each city to the map. 
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)

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

# 11b. Display the figure
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11893647249847777, 'fraction_numerical': 0.009945199918814695, 'mean_word_length': 4.350705754614549, 'pattern_counts': {'":': 3, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '503460', 'license': 'Apache-2.0', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1585, 'n_words': 510, 'path': 'Vacation_Search/Vacation_Search.ipynb', 'repo_name': 'cdpeters/weather-and-map-apis-python', 'size': '4927'}