<jupyter_start><jupyter_text>Deliverable 2. Create a Customer Travel Destinations Map.<jupyter_code># Dependencies and Setup
import pandas as pd
import requests
import gmaps
import sys
sys.path.append('..')

# Import API key
from config import g_key

# Configure gmaps API key
gmaps.configure(api_key=g_key)
# 1. Import the WeatherPy_database.csv file. 

city_data_df = pd.read_csv("../Weather_Database/WeatherPy_database.csv")
city_data_df.head()<jupyter_output><empty_output><jupyter_text>Ask for customer input and convert the input to a floating number.<jupyter_code># 2. Prompt the user to enter minimum and maximum temperature criteria 
min_temp = float(input("What is the minimum temperature (in F) would you like for your trip?  "))
max_temp = float(input("What is the maximum temperature (in F) would you like for your trip?  "))<jupyter_output>What is the minimum temperature (in F) would you like for your trip?  75
What is the maximum temperature (in F) would you like for your trip?  90<jupyter_text>Create a new DataFrame using loc method. Determine and remove empty rows.<jupyter_code># 3. Filter the city_data_df DataFrame using the input statements to create a new DataFrame using the loc method.
vacation_city_df = city_data_df.loc[(city_data_df["Max Temp"] <= max_temp) & \
                                   (city_data_df["Max Temp"] >= min_temp)]
vacation_city_df.head(10)
# 4a. Determine if there are any empty rows.

# Doesn't seem to work. Try isnull().sum()
vacation_city_df.count()
# Determine the null values using isnull().sum()

vacation_city_df.isnull().sum()
# 4b. Drop any empty rows and create a new DataFrame that doesn’t have empty rows.<jupyter_output><empty_output><jupyter_text>There is no null rows here.  We would use dropna() method to remove the empty rows in in Step 3 The command would be saved in a different DataFrame: clean_vacation_df = vacation_city_df.dropna( )  Create a Hotel Information DataFrame with relevant information<jupyter_code># 5a. Create DataFrame called hotel_df to store hotel names along with city, country, max temp, and coordinates.
hotel_df = vacation_city_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)
# 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 location parameter --> Latidue and Longitude to a Location key --FMJ
    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"
    
    # 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.
    try:
        hotel_df.loc[index, "Hotel Name"] = hotels["results"][0]["name"]
    except (IndexError):
        print("Hotel not found....skipping")<jupyter_output>Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping
Hotel not found....skipping<jupyter_text>There are cities with no hotels. Need to clean it up. I will use the loc[ ] method.<jupyter_code>hotel_df.head()<jupyter_output><empty_output><jupyter_text>These are the cities with no hotels<jupyter_code># These are the cities with no hotel
no_hotel = hotel_df.loc[(hotel_df["Hotel Name"] == "")]

no_hotel.head()<jupyter_output><empty_output><jupyter_text>A new Clean DataFrame containing cities with hotels.<jupyter_code># 7. Drop the rows where there is no Hotel Name.
# Make a clean hotel data frame.
clean_hotel_df = hotel_df.loc[(hotel_df["Hotel Name"] != "")]
clean_hotel_df<jupyter_output><empty_output><jupyter_text>Generate an Output File (CSV)<jupyter_code># 8a. Create the output File (CSV)
output_data_file = "WeatherPy_vacation.csv"

# 8b. Export the City_Data into a csv
clean_hotel_df.to_csv(output_data_file, index_label="City_ID")
# 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} \N{DEGREE SIGN} 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"]]

# Store the DataFrame Row.
hotel_info = [info_box_template.format(**row) for index, row in clean_hotel_df.iterrows()]<jupyter_output><empty_output><jupyter_text>Plot the Data and save the figure<jupyter_code># 11a. Add a marker layer for each city to the map. 
marker_layer = gmaps.marker_layer(locations, info_box_content = hotel_info)

# 11b. Display the figure
# Assign the figure variable.
fig = gmaps.figure(center = (30.0, 31.0), zoom_level = 1.5)
fig.add_layer(marker_layer)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11004784688995216, 'fraction_numerical': 0.00888585099111415, 'mean_word_length': 4.521698113207547, 'pattern_counts': {'":': 3, '<': 54, '<?xml version=': 0, '>': 55, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '96825', 'license': 'CECILL-B', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1876, 'n_words': 646, 'path': 'Vacation_Search/Vacation_Search.ipynb', 'repo_name': 'fmohiudd/World_Weather_Analysis', 'size': '5852'}