Skip to content

Commit 5fa2c02

Browse files
committed
Updates
1 parent 991477d commit 5fa2c02

21 files changed

+3329
-1
lines changed

Images/equatorsign.png

888 KB
Loading

Images/heatmap.png

484 KB
Loading

Images/hotel_map.png

410 KB
Loading

README.md

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,119 @@
1-
# Python_Api_Challenge
1+
# Python API Homework - What's the Weather Like?
2+
3+
## Background
4+
5+
Whether financial, political, or social -- data's true power lies in its ability to answer questions definitively. So let's take what you've learned about Python requests, APIs, and JSON traversals to answer a fundamental question: "What's the weather like as we approach the equator?"
6+
7+
Now, we know what you may be thinking: _"Duh. It gets hotter..."_
8+
9+
But, if pressed, how would you **prove** it?
10+
11+
![Equator](Images/equatorsign.png)
12+
13+
### Before You Begin
14+
15+
1. Create a new repository for this project called `python-api-challenge`. **Do not add this homework to an existing repository**.
16+
17+
2. Clone the new repository to your computer.
18+
19+
3. Inside your local git repository, create a directory for both of the Python Challenges. Use folder names corresponding to the challenges: **WeatherPy**.
20+
21+
4. Inside the folder that you just created, add new files called `WeatherPy.ipynb` and `VacationPy.ipynb`. These will be the main scripts to run for each analysis.
22+
23+
5. Push the above changes to GitHub.
24+
25+
## Part I - WeatherPy
26+
27+
In this example, you'll be creating a Python script to visualize the weather of 500+ cities across the world of varying distance from the equator. To accomplish this, you'll be utilizing a [simple Python library](https://pypi.python.org/pypi/citipy), the [OpenWeatherMap API](https://openweathermap.org/api), and a little common sense to create a representative model of weather across world cities.
28+
29+
Your first requirement is to create a series of scatter plots to showcase the following relationships:
30+
31+
* Temperature (F) vs. Latitude
32+
* Humidity (%) vs. Latitude
33+
* Cloudiness (%) vs. Latitude
34+
* Wind Speed (mph) vs. Latitude
35+
36+
After each plot add a sentence or too explaining what the code is and analyzing.
37+
38+
Your second requirement is to run linear regression on each relationship, only this time separating them into Northern Hemisphere (greater than or equal to 0 degrees latitude) and Southern Hemisphere (less than 0 degrees latitude):
39+
40+
* Northern Hemisphere - Temperature (F) vs. Latitude
41+
* Southern Hemisphere - Temperature (F) vs. Latitude
42+
* Northern Hemisphere - Humidity (%) vs. Latitude
43+
* Southern Hemisphere - Humidity (%) vs. Latitude
44+
* Northern Hemisphere - Cloudiness (%) vs. Latitude
45+
* Southern Hemisphere - Cloudiness (%) vs. Latitude
46+
* Northern Hemisphere - Wind Speed (mph) vs. Latitude
47+
* Southern Hemisphere - Wind Speed (mph) vs. Latitude
48+
49+
After each pair of plots explain what the linear regression is modeling such as any relationships you notice and any other analysis you may have.
50+
51+
**Optional** You will be creating multiple linear regression plots. To optimize your code, write a function that creates the linear regression plots.
52+
53+
Your final notebook must:
54+
55+
* Randomly select **at least** 500 unique (non-repeat) cities based on latitude and longitude.
56+
* Perform a weather check on each of the cities using a series of successive API calls.
57+
* Include a print log of each city as it's being processed with the city number and city name.
58+
* Save a CSV of all retrieved data and a PNG image for each scatter plot.
59+
60+
### Part II - VacationPy
61+
62+
Now let's use your skills in working with weather data to plan future vacations. Use jupyter-gmaps and the Google Places API for this part of the assignment.
63+
64+
* **Note:** if you having trouble displaying the maps try running `jupyter nbextension enable --py gmaps` in your environment and retry.
65+
66+
* Create a heat map that displays the humidity for every city from the part I of the homework.
67+
68+
![heatmap](Images/heatmap.png)
69+
70+
* Narrow down the DataFrame to find your ideal weather condition. For example:
71+
72+
* A max temperature lower than 80 degrees but higher than 70.
73+
74+
* Wind speed less than 10 mph.
75+
76+
* Zero cloudiness.
77+
78+
* Drop any rows that don't contain all three conditions. You want to be sure the weather is ideal.
79+
80+
* **Note:** Feel free to adjust to your specifications but be sure to limit the number of rows returned by your API requests to a reasonable number.
81+
82+
* Using Google Places API to find the first hotel for each city located within 5000 meters of your coordinates.
83+
84+
* Plot the hotels on top of the humidity heatmap with each pin containing the **Hotel Name**, **City**, and **Country**.
85+
86+
![hotel map](Images/hotel_map.png)
87+
88+
As final considerations:
89+
90+
* Create a new GitHub repository for this project called `API-Challenge` (note the kebab-case). **Do not add to an existing repo**
91+
* You must complete your analysis using a Jupyter notebook.
92+
* You must use the Matplotlib or Pandas plotting libraries.
93+
* For Part I, you must include a written description of three observable trends based on the data.
94+
* You must use proper labeling of your plots, including aspects like: Plot Titles (with date of analysis) and Axes Labels.
95+
* For max intensity in the heat map, try setting it to the highest humidity found in the data set.
96+
97+
## Hints and Considerations
98+
99+
* The city data you generate is based on random coordinates as well as different query times; as such, your outputs will not be an exact match to the provided starter notebook.
100+
101+
* You may want to start this assignment by refreshing yourself on the [geographic coordinate system](http://desktop.arcgis.com/en/arcmap/10.3/guide-books/map-projections/about-geographic-coordinate-systems.htm).
102+
103+
* Next, spend the requisite time necessary to study the OpenWeatherMap API. Based on your initial study, you should be able to answer basic questions about the API: Where do you request the API key? Which Weather API in particular will you need? What URL endpoints does it expect? What JSON structure does it respond with? Before you write a line of code, you should be aiming to have a crystal clear understanding of your intended outcome.
104+
105+
* A starter code for Citipy has been provided. However, if you're craving an extra challenge, push yourself to learn how it works: [citipy Python library](https://pypi.python.org/pypi/citipy). Before you try to incorporate the library into your analysis, start by creating simple test cases outside your main script to confirm that you are using it correctly. Too often, when introduced to a new library, students get bogged down by the most minor of errors -- spending hours investigating their entire code -- when, in fact, a simple and focused test would have shown their basic utilization of the library was wrong from the start. Don't let this be you!
106+
107+
* Part of our expectation in this challenge is that you will use critical thinking skills to understand how and why we're recommending the tools we are. What is Citipy for? Why would you use it in conjunction with the OpenWeatherMap API? How would you do so?
108+
109+
* In building your script, pay attention to the cities you are using in your query pool. Are you getting coverage of the full gamut of latitudes and longitudes? Or are you simply choosing 500 cities concentrated in one region of the world? Even if you were a geographic genius, simply rattling 500 cities based on your human selection would create a biased dataset. Be thinking of how you should counter this. (Hint: Consider the full range of latitudes).
110+
111+
* Once you have computed the linear regression for one chart, the process will be similar for all others. As a bonus, try to create a function that will create these charts based on different parameters.
112+
113+
* Remember that each coordinate will trigger a separate call to the Google API. If you're creating your own criteria to plan your vacation, try to reduce the results in your DataFrame to 10 or fewer cities.
114+
115+
* Lastly, remember -- this is a challenging activity. Push yourself! If you complete this task, then you can safely say that you've gained a strong mastery of the core foundations of data analytics and it will only go better from here. Good luck!
116+
117+
### Copyright
118+
119+
Trilogy Education Services © 2019. All Rights Reserved.

WeatherPy/VacationPy.ipynb

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# VacationPy\n",
8+
"----\n",
9+
"\n",
10+
"#### Note\n",
11+
"* 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."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# Dependencies and Setup\n",
21+
"import matplotlib.pyplot as plt\n",
22+
"import pandas as pd\n",
23+
"import numpy as np\n",
24+
"import requests\n",
25+
"import gmaps\n",
26+
"import os\n",
27+
"\n",
28+
"# Import API key\n",
29+
"from api_keys import g_key"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"### Store Part I results into DataFrame\n",
37+
"* Load the csv exported in Part I to a DataFrame"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": null,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"\n"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {},
52+
"source": [
53+
"### Humidity Heatmap\n",
54+
"* Configure gmaps.\n",
55+
"* Use the Lat and Lng as locations and Humidity as the weight.\n",
56+
"* Add Heatmap layer to map."
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": []
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": []
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"### Create new DataFrame fitting weather criteria\n",
78+
"* Narrow down the cities to fit weather conditions.\n",
79+
"* Drop any rows will null values."
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": []
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"### Hotel Map\n",
94+
"* Store into variable named `hotel_df`.\n",
95+
"* Add a \"Hotel Name\" column to the DataFrame.\n",
96+
"* Set parameters to search for hotels with 5000 meters.\n",
97+
"* Hit the Google Places API for each city's coordinates.\n",
98+
"* Store the first Hotel result into the DataFrame.\n",
99+
"* Plot markers on top of the heatmap."
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": []
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": []
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"# NOTE: Do not change any of the code in this cell\n",
123+
"\n",
124+
"# Using the template add the hotel marks to the heatmap\n",
125+
"info_box_template = \"\"\"\n",
126+
"<dl>\n",
127+
"<dt>Name</dt><dd>{Hotel Name}</dd>\n",
128+
"<dt>City</dt><dd>{City}</dd>\n",
129+
"<dt>Country</dt><dd>{Country}</dd>\n",
130+
"</dl>\n",
131+
"\"\"\"\n",
132+
"# Store the DataFrame Row\n",
133+
"# NOTE: be sure to update with your DataFrame name\n",
134+
"hotel_info = [info_box_template.format(**row) for index, row in hotel_df.iterrows()]\n",
135+
"locations = hotel_df[[\"Lat\", \"Lng\"]]"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"# Add marker layer ontop of heat map\n",
145+
"\n",
146+
"\n",
147+
"# Display figure\n"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {},
154+
"outputs": [],
155+
"source": []
156+
}
157+
],
158+
"metadata": {
159+
"kernelspec": {
160+
"display_name": "Python 3",
161+
"language": "python",
162+
"name": "python3"
163+
},
164+
"language_info": {
165+
"codemirror_mode": {
166+
"name": "ipython",
167+
"version": 3
168+
},
169+
"file_extension": ".py",
170+
"mimetype": "text/x-python",
171+
"name": "python",
172+
"nbconvert_exporter": "python",
173+
"pygments_lexer": "ipython3",
174+
"version": "3.7.6"
175+
},
176+
"latex_envs": {
177+
"LaTeX_envs_menu_present": true,
178+
"autoclose": false,
179+
"autocomplete": true,
180+
"bibliofile": "biblio.bib",
181+
"cite_by": "apalike",
182+
"current_citInitial": 1,
183+
"eqLabelWithNumbers": true,
184+
"eqNumInitial": 1,
185+
"hotkeys": {
186+
"equation": "Ctrl-E",
187+
"itemize": "Ctrl-I"
188+
},
189+
"labels_anchors": false,
190+
"latex_user_defs": false,
191+
"report_style_numbering": false,
192+
"user_envs_cfg": false
193+
}
194+
},
195+
"nbformat": 4,
196+
"nbformat_minor": 2
197+
}

0 commit comments

Comments
 (0)