<jupyter_start><jupyter_text>VacationPy---The goal is to find a vocation city or cities with ideal weather conditions based on the custom criteria using jupyter-gmaps and the Google Places API.---<jupyter_code>#!jupyter nbextension enable --py --sys-prefix widgetsnbextension
#!jupyter nbextension enable --py --sys-prefix gmaps
# Dependencies and Setup:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import gmaps
import os
import json

# Import API key:
from api_keys import g_key<jupyter_output><empty_output><jupyter_text>--- Loading City Data From the Home Work Part 1<jupyter_code># File to Load:
file_to_load='../weatherpy/output_data/cities.csv' # csv file created in part I of homework 

# Read csv cities file and store into data frame:
city_data=pd.read_csv(file_to_load)
city_data.head()
city_data.count()<jupyter_output><empty_output><jupyter_text>--- Humidity Heatmap<jupyter_code># Determan max humidity level in the city data frame:
max_hum=city_data['Humidity (%)'].max()
max_hum
# Configure gmaps with API key:
gmaps.configure(api_key=g_key)
# Store 'Lat' and 'Lng' into  locations: 
city_data=city_data.dropna() # drop NaN values
locations=city_data[['Lat', 'Lng']].astype(float)

# Convert humidity level to float and store:
humidity_rate=city_data['Humidity (%)'].astype(float)
# Create a humidity heat map layer:
fig=gmaps.figure()

heat_layer=gmaps.heatmap_layer(locations, weights=humidity_rate, 
                                 dissipating=False, max_intensity=max_hum,
                                 point_radius=3)

fig.add_layer(heat_layer)
fig<jupyter_output><empty_output><jupyter_text>--- New DataFrame Fitting Custom Weather Criteria<jupyter_code># Create new data frame with requested weather conditions:
city_data_narrow=city_data[(city_data['Max Temp (F)'] < 80) &
                             (city_data['Max Temp (F)'] > 65) &
                             (city_data['Wind Speed (mph)'] < 10) &
                             (city_data['Cloudiness (%)'] < 15) &
                             (city_data['Humidity (%)'] < 30)]
city_data_narrow=city_data_narrow.dropna() # drop any rows will null values
city_data_narrow.count()
city_data_narrow.head(6)
# Set up lists to hold response info:
name=[]         # list for hotel name
city=[]         # list for hotel city
country=[]      # list for hotel country
lat=[]          # list for hotel latitude
lng=[]          # list for hotel longitude

# Loop through the list of cities and perform a request for data on each and add to corresponding lists:

count=1 # set counter to start value 1 for printouts of the current set count

print('Beginning Data Retrieval')     
print('-----------------------------')
for i in range(len(city_data_narrow)) : 
   
    lati=str(city_data_narrow.iloc[i, 3])    
    lngi=str(city_data_narrow.iloc[i, 4])
    
    target_coordinates=lati + ', ' + lngi  
    target_search='Hotel'
    target_radius=5000
    target_type='lodging'

    # Set up a parameters dictionary:
    params={
        'location': target_coordinates,
        'keyword': target_search,
        'radius': target_radius,
        'type': target_type,
        'key': g_key
    }

    # Base url:
    base_url='https://maps.googleapis.com/maps/api/place/nearbysearch/json'

    # Run a request using the above params dictionary:
    response=requests.get(base_url, params=params)
    #print(response.url)
    
    # Convert response to json:
    places_data=response.json()
    #print(json.dumps(places_data, indent=4, sort_keys=True))
    
    # Print user feedback: 
    print('Looking for Hotels near: ' + str(city_data_narrow.iloc[i, 0]) + ' | Record ' + str(count) + ' of Total ' + str(len(city_data_narrow)))
     
    # Add requested data to  result lists:
    try:                                             # ignore errors in response
        name.append(places_data['results'][0]['name'])
        city.append(city_data_narrow.iloc[i, 0])
        country.append(city_data_narrow.iloc[i, 1])
        lat.append(places_data['results'][0]['geometry']['location']['lat'])
        lng.append(places_data['results'][0]['geometry']['location']['lng'])
    except IndexError:
        print('No Hotel Near Location... Skipping...') # in case one of the responses comes back with error "IndexError"
                                                           # which could be no hotel near location 
  
    count=count+1
    
# Print Ending Log Statement:
print('-------------------------------')
print('Data Retrieval Complete')
print('-------------------------------')
# Create a data frame from api call list:
hotel_dict={
    'City': city,
    'Country': country,
    'Lat': lat,
    'Lng': lng,
    'Hotel Name': name
}
hotel_df=pd.DataFrame(hotel_dict)
hotel_df.count()
hotel_df<jupyter_output><empty_output><jupyter_text>--- Hotel Map for Vacation Cities<jupyter_code># 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']]
# Customize the size of the figure:
figure_layout={
    'width': '955px',
    'height': '600px',
    'border': '1px solid black',
    'padding': '1px',
    'margin': '0 auto 0 auto'
}
fig=gmaps.figure(layout=figure_layout)

# Assign the marker layer to a variable:
markers=gmaps.marker_layer(locations, info_box_content=hotel_info)
# Add the layer to the map:
fig.add_layer(markers)
fig
# Create a combined map:
fig=gmaps.figure()

fig.add_layer(heat_layer)
fig.add_layer(markers)

fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13332195288494367, 'fraction_numerical': 0.006657562307954934, 'mean_word_length': 3.2672978878368535, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 36, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '403193', 'license': 'ADSL', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1848, 'n_words': 506, 'path': 'WeatherPy/VacationPy.ipynb', 'repo_name': 'DataTell/python-api-challenge', 'size': '5858'}