Skip to content

Interact with API's to gather current weather conditions for global random cities. Use the gathered Weather data to determine vacation opportunities by identifying the nearest hotel.

Notifications You must be signed in to change notification settings

RJBarker/python-api-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Python-API-Challenge

Challenge Description

This challenge has been split into two sub-challenges. The first 'WeatherPy' tasked me with obtaining the weather from the 'OpenWeatherMap API' for 500 cities across the world, with the data collected being output to a CSV file before being read into the second task 'VacationPy'. In the second task, using the data within the CSV, locate hotels using the 'Geoapify API' within certain Cities to plan my next vacation!

WeatherPy

Obtaining the Data

- Citipy libary code already provided to obtain a random selection of Longitude and Latitude values and the nearest City.
- Using the 'OpenWeatherMap API' iterate through the cities identified by the Citipy:
    - Through the JSON result for each city obtain:
        - Latitude
        - Longitude
        - Max Temp
        - Humidity
        - Cloud cover
        - Wind speed
        - Country code
        - Date
    - Append the obtained data to the 'city_data' list
- Create a dataframe from the 'city_data' list
    - Save the dataframe to CSV ready for the 'VacationPy' task

Generate Scatter plots

- Using the data collected, generate scatter plots for:
    - Latitude vs Temperature (c)
    - Latitude vs. Humidity (%)
    - Latitude vs. Cloudiness (%)
    - Latitude vs. Wind Speed (m/s)
- Note: To save time/repetitve coding, I created a function to generate the base scatter plots and then just added additional lines for the titles/labels

Compute Linear Regression

- Separate the Citie's from the previous dataframe into Northern and Southern Hemisphere dataframes
- Create a function to compute the linear regression for the previously created plots, broken down into Northern and Southern Hemisphere dataframes
- Create plots, linear regression and Line Equation for the following relationships:
    - 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

VacationPy

Plot the Cities on a World Map

- Using the CSV from the previous 'city_data_df' plot each City on a hvplot world map
- The size of the marker should be determined by the 'Humidity' value of each City
- And each City point should be coloured differently

Add conditions to limit the number of Cities

- I added three conditions to reducde the number of cities down:
    - Temperature should be <= 30
    - Temperature should be >= 20
    - Cloudiness should be == 0
- This reduced dataset was then renamed to 'hotel_df' consisting of the following columns:
    - City
    - Country
    - Longitude
    - Latitude
    - Humidity
    - Hotel Name - This was an empty column added to the dataframe ready for the next task

Locate nearest Hotel to each City in 'hotel_df'

- Using the 'Geoapify API' iterate through each City within the 'hotel_df' and find:
    - The nearest Hotel
    - Within 10km of the Latitude and Longitude of the city
    - Append the name of the hotel to the 'Hotel Name' column of the DataFrame
- I added an additional step to filter out any Cities where a hotel was not found within the search area
- Using the 'hotel_df' generate another world map to show each City which met the previous conditions set
    - Add the 'Hotel Name' and 'Country' to the hover message for each point

Notes

After pushing the VacationPy.ipynb file to GitHub, I noticed the maps from the hvplot were not showing within the GitHub Jupyter Notebook viewer. I've added PNG files of the maps into an 'output_data' folder within the 'VacationPy' directory to demonstate successful plotting.

References

- Code for converting Unix timestamp from 'Date' column to a Date Format - https://stackoverflow.com/a/75222939/21871037
- Code used in an attempt to stop the labels/titles being cut off with the 'savefig' function - https://ecoagi.ai/topics/Matplotlib/matplotlib-savefig-cuts-off-labels#saving-the-figure-with-bbox_inchestight
- Initial coding - edX Boot Camps LLC
- Weather data - OpenWeatherMap API
- Hotel Data - Geoapify API

About

Interact with API's to gather current weather conditions for global random cities. Use the gathered Weather data to determine vacation opportunities by identifying the nearest hotel.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published