-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVacationPy.py
More file actions
158 lines (96 loc) · 2.88 KB
/
Copy pathVacationPy.py
File metadata and controls
158 lines (96 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
# coding: utf-8
# # 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.
# In[12]:
# 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
# ### Store Part I results into DataFrame
# * Load the csv exported in Part I to a DataFrame
# In[13]:
g_key
# In[14]:
df1 = pd.read_csv('../output_data/cities.csv')
# ### Humidity Heatmap
# * Configure gmaps.
# * Use the Lat and Lng as locations and Humidity as the weight.
# * Add Heatmap layer to map.
# In[15]:
gmaps.configure(api_key=g_key)
# In[16]:
locations = df1[["Lat", "Lng"]]
humidity = df1["Humidity"]
fig1 = gmaps.Map()
heat = gmaps.heatmap_layer(locations, weights=humidity)
fig1.add_layer(heat)
# ### Create new DataFrame fitting weather criteria
# * Narrow down the cities to fit weather conditions.
# * Drop any rows will null values.
# In[17]:
idf = df1.loc[df1['Max Temp'] < 80, :]
idf = idf.loc[idf['Max Temp'] > 70, :]
idf = idf.loc[idf['Wind Speed'] < 10, :]
idf = idf.loc[idf['Cloudiness'] == 0, :]
# ### 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.
# In[21]:
hotel_df = idf
hotel_df['Hotel Name'] = np.nan
param1 = "Hotel"
param2 = 5000
param3 = "lodging"
counter = 0
for index, row in hotel_df.iterrows():
params = {
"location": f"{row['Lat']}, {row['Lng']}",
"keyword": param1,
"radius": param2,
"type": param3,
"key": g_key
}
base = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
response = requests.get(base, params=params)
response_json = response.json()
results = response_json['results']
if len(results) > 0:
name = response_json['results'][0]['name']
hotel_df.iloc[idx, -1] = name
counter = counter + 1
narrowed_city_df = hotel_df
# In[22]:
# 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 narrowed_city_df.iterrows()]
locations = hotel_df[["Lat", "Lng"]]
# In[23]:
# Add marker layer ontop of heat map
layer = gmaps.marker_layer(locations, info_box_content=hotel_info)
fig1.add_layer(layer)
# Display Map
fig1
# In[ ]:
# In[ ]: