Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewjmack/python-api-challenge
Homework repo for module 6
https://github.com/andrewjmack/python-api-challenge
Last synced: about 7 hours ago
JSON representation
Homework repo for module 6
- Host: GitHub
- URL: https://github.com/andrewjmack/python-api-challenge
- Owner: andrewjmack
- Created: 2024-03-26T18:59:50.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-01T22:18:32.000Z (8 months ago)
- Last Synced: 2024-04-02T03:35:54.784Z (8 months ago)
- Language: Jupyter Notebook
- Size: 3.9 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# python-API-challenge
- Andrew Mack | Homework repo for module 6## Repo contents:
- starter_code
- WeatherPy
- WeatherPy.ipynb
- output_data
- cities.csv
- four .png files of various chart outputs
- VacationPy
- VacationPy.ipynb
- output_data
- cities.csv
- README.md
- .gitignore# Summary:
- This module consisted of two challenges which are described in greater detail further below in this README file.## Part 1: WeatherPy
- In this deliverable, you'll create a Python script to visualize the weather of over 500 cities of varying distances from the equator. You'll use the citipy Python libraryLinks to an external site., the OpenWeatherMap APILinks to an external site., and your problem-solving skills to create a representative model of weather across cities.## Part 2: VacationPy
- In this deliverable, you'll use your weather data skills to plan future vacations. Also, you'll use Jupyter notebooks, the geoViews Python library, and the Geoapify API.# Resources
- Module class lessons and activities
- Tutoring session with Reza
- Openweathermap API documentation: https://openweathermap.org/current
- Geoapify API documentation: https://apidocs.geoapify.com/docs/places/#categories
- reference on time library to correctly label weather chart dates: https://www.geeksforgeeks.org/python-time-module/
- defining py functions, to define scatterplot function in weather challenge: https://www.w3schools.com/python/python_functions.asp
- reference for annotating regression line:
https://matplotlib.org/2.0.2/api/pyplot_api.html#matplotlib.pyplot.annotate
- customization options for hvplot: https://hvplot.holoviz.org/user_guide/Customization.html
- reference to ID potential null values in a dataframe https://stackoverflow.com/questions/43424199/display-rows-with-one-or-more-nan-values-in-pandas-dataframe
- adding additional labels in hover windows of hvplot:
https://discourse.holoviz.org/t/add-an-extra-field-when-hovering-in-hvplot-scatter/2331-----------
# Background
Data's true power is its ability to definitively answer questions. So, let's take what you've learned about Python requests, APIs, and JSON traversals to answer a fundamental question: "What is the weather like as we approach the equator?"Now, we know what you may be thinking: “That’s obvious. It gets hotter.” But, if pressed for more information, how would you prove that?
Before You Begin
Create a new repository for this project called python-api-challenge. Do not add this homework to an existing repository.Clone the new repository to your computer.
Inside your local Git repository, create a directory for this assignment. Use a folder name that corresponds to the Challenges, such as WeatherPy.
Inside the folder you just created, add the files called api_keys.py, WeatherPy.ipynb, and VacationPy.ipynb that you will find in the starter code ZIP file provided. These will be the main scripts to run for each analysis.
Before you push your changes to GitHub, add a .gitignore file.
Add a .gitignore File
For this assignment, you will need to add a .gitignore file to your repo. Doing so will prevent the api_keys.py file that contains your API key from being shared with the public. If you skip this step, anyone using GitHub could copy and use your API key, and you may incur charges as a result.To get started, type git status in the command line to see a list of all the untracked files that you have created so far.
To add only the WeatherPy.ipynb file to GitHub, for example, type git add WeatherPy.ipynb. Keep in mind that you would have to add each file individually when adding or updating a file. A more efficient solution is to add all of the files that you don't want to track to the .gitignore file.
Before adding your files to GitHub, add api_keys.py to the .gitignore file by following these steps:
Open your python-api-challenge GitHub folder in VS Code.
Open the .gitignore file and type the following code on the first line:
Adding config.py file.
api_keys.py
In the command line, type git status and press Enter. The output should indicate that the .gitignore file has been modified and the api_keys.py file is untracked.Use git add, git commit, and git push to commit the modifications to the .gitignore, WeatherPy.ipynb and VacationPy.ipynb files to GitHub.
On GitHub, the only new python files you should find are WeatherPy.ipynb and VacationPy.ipynb.
Files
Download the following files to help you get started:Module 6 Challenge filesLinks to an external site.
Instructions
This activity is broken down into two deliverables, WeatherPy and VacationPy.### Part 1: WeatherPy
In this deliverable, you'll create a Python script to visualize the weather of over 500 cities of varying distances from the equator. You'll use the citipy Python libraryLinks to an external site., the OpenWeatherMap APILinks to an external site., and your problem-solving skills to create a representative model of weather across cities.For this part, you'll use the WeatherPy.ipynb Jupyter notebook provided in the starter code ZIP file. The starter code will guide you through the process of using your Python coding skills to develop a solution to address the required functionalities.
To get started, the code required to generate random geographic coordinates and the nearest city to each latitude and longitude combination is provided.
Requirement 1: Create Plots to Showcase the Relationship Between Weather Variables and Latitude
To fulfill the first requirement, you'll use the OpenWeatherMap API to retrieve weather data from the cities list generated in the starter code. Next, you'll create a series of scatter plots to showcase the following relationships:Latitude vs. Temperature
Latitude vs. Humidity
Latitude vs. Cloudiness
Latitude vs. Wind Speed
Requirement 2: Compute Linear Regression for Each Relationship
To fulfill the second requirement, compute the linear regression for each relationship. Separate the plots into Northern Hemisphere (greater than or equal to 0 degrees latitude) and Southern Hemisphere (less than 0 degrees latitude). You may find it helpful to define a function in order to create the linear regression plots.Next, create a series of scatter plots. Be sure to include the linear regression line, the model's formula, and the r values as you can see in the following image
Sample scatter plot with the linear regression line.
You should create the following plots:
Northern Hemisphere: Temperature vs. Latitude
Southern Hemisphere: Temperature vs. Latitude
Northern Hemisphere: Humidity vs. Latitude
Southern Hemisphere: Humidity vs. Latitude
Northern Hemisphere: Cloudiness vs. Latitude
Southern Hemisphere: Cloudiness vs. Latitude
Northern Hemisphere: Wind Speed vs. Latitude
Southern Hemisphere: Wind Speed vs. Latitude
After each pair of plots, explain what the linear regression is modeling. Describe any relationships that you notice and any other findings you may uncover.
### Part 2: VacationPy
In this deliverable, you'll use your weather data skills to plan future vacations. Also, you'll use Jupyter notebooks, the geoViews Python library, and the Geoapify API.The code needed to import the required libraries and load the CSV file with the weather and coordinates data for each city created in Part 1 is provided to help you get started.
Your main tasks will be to use the Geoapify API and the geoViews Python library and employ your Python skills to create map visualizations.
To succeed on this deliverable of the assignment, open the VacationPy.ipynb starter code and complete the following steps:
Create a map that displays a point for every city in the city_data_df DataFrame as shown in the following image. The size of the point should be the humidity in each city.
Humidity map
Narrow down the city_data_df DataFrame to find your ideal weather condition. For example:
A max temperature lower than 27 degrees but higher than 21
Wind speed less than 4.5 m/s
Zero cloudiness
NOTE
Feel free to adjust your specifications but make sure to set a reasonable limit to the number of rows returned by your API requests.Create a new DataFrame called hotel_df to store the city, country, coordinates, and humidity.
For each city, use the Geoapify API to find the first hotel located within 10,000 meters of your coordinates.
Add the hotel name and the country as additional information in the hover message for each city on the map as in the following image:
Hotel map
Hints and Considerations
The city data that you generate is based on random coordinates and different query times, so your outputs will not be an exact match to the provided starter notebook.If you'd like a refresher on the geographic coordinate system, this siteLinks to an external site. has great information.
Take some time 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 have a crystal-clear understanding of your intended outcome.
A starter code for citipy has been provided. However, if you're craving an extra challenge, push yourself to learn how it works by using the citipy Python libraryLinks to an external site.. Before you try to incorporate the library in your analysis, start with simple test cases outside of your main script to confirm that you are using it correctly. Often, when introduced to a new library, learners spend hours trying to figure out errors in their code when a simple test case can save you a lot of time and frustration.
You will need to apply your critical thinking skills to understand how and why we're recommending these tools. What is citipy used for? Why would you use it in conjunction with the OpenWeatherMap API? How would you do so?
While building your script, pay attention to the cities you are using in your query pool. Are you covering the full range of latitudes and longitudes? Or are you choosing 500 cities from one region of the world? Even if you were a geography genius, simply listing 500 cities based on your personal selection would create a biased dataset. Try to think of ways that you can counter these selection issues.
Hint: Consider the full range of latitudes.
Once you have computed the linear regression for one relationship, you will follow a similar process for all other charts. Optionally, try to create a function that will create these charts based on different parameters. (Note: there will be no extra points for completing this.)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.
Ensure that your repository has regular commits and a thorough README.md file.
Lastly, remember that this is a challenging activity. Push yourself! If you complete this task, you can safely say that you've gained a strong understanding of the core foundations of data analytics, and it will only get better from here. Good luck!
## Requirements
### The requirements for "Part 1: WeatherPy" are the following
Create Plots to Showcase the Relationship Between Weather Variables and Latitude (30 points)
Use the OpenWeatherMap API to retrieve weather data from the cities list generated in the started code (10 points)Create a scatter plot to showcase the relationship between Latitude vs. Temperature (5 points)
Create a scatter plot to showcase the relationship between Latitude vs. Humidity (5 points)
Create a scatter plot to showcase the relationship between Latitude vs. Cloudiness (5 points)
Create a scatter plot to showcase the relationship between Latitude vs. Wind Speed (5 points)
Compute Linear Regression for Each Relationship (40 points)
Linear regression scatter plot for Northern Hemisphere: Temperature (C) vs. Latitude (5 points)Linear regression scatter plot for Southern Hemisphere: Temperature (C) vs. Latitude (5 points)
Linear regression scatter plot for Northern Hemisphere: Humidity (%) vs. Latitude (5 points)
Linear regression scatter plot for Southern Hemisphere: Humidity (%) vs. Latitude (5 points)
Linear regression scatter plot for Northern Hemisphere: Cloudiness (%) vs. Latitude (5 points)
Linear regression scatter plot for Southern Hemisphere: Cloudiness (%) vs. Latitude (5 points)
Linear regression scatter plot for Northern Hemisphere: Wind Speed (m/s) vs. Latitude (5 points)
Linear regression scatter plot for Southern Hemisphere: Wind Speed (m/s) vs. Latitude (5 points)
### The requirements for "Part 2: VacationPy" are the following (30 points)
Create a map that displays a point for every city in the city_data_df DataFrame (5 points)Narrow down the city_data_df DataFrame to find your ideal weather condition (5 points)
For each city in the hotel_df DataFrame, use the Geoapify API to find the first hotel located within 10,000 metres of your coordinates (10 points)
Add the hotel name and the country as additional information in the hover message for each city in the map. (10 points)