bfraser4 / SQL-Alchemy-Challenge

Connect to SQL DB utilizing SQLAlchemy. Perform an analysis of weather data utilizing Python and Pandas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQLAlchemy Climate Analysis & Flask API Application Build

Part 1: Climate Analysis and Exploration

In this section, you’ll use Python and SQLAlchemy to perform basic climate analysis and data exploration of your climate database. Complete the following tasks by using SQLAlchemy ORM queries, Pandas, and Matplotlib.

  • Use SQLAlchemy’s create_engine to connect to your SQLite database.

carbon (11)

  • Use SQLAlchemy’s automap_base() to reflect your tables into classes and save a reference to those classes called Station and Measurement.

carbon (12)

  • Link Python to the database by creating a SQLAlchemy session.

carbon (13)

Precipitation Analysis

To perform an analysis of precipitation in the area, do the following:

  • Find the most recent date in the dataset.

carbon (14)

  • Using this date, retrieve the previous 12 months of precipitation data by querying the 12 previous months of data. Select only the date and prcp values.

carbon (15)

  • Load the query results into a Pandas DataFrame, and set the index to the date column. Sort the DataFrame values by date.

carbon (16)

  • Plot the results by using the DataFrame plot method.

carbon (17) Screen Shot 2023-01-30 at 7 58 15 PM

  • Use Pandas to print the summary statistics for the precipitation data.

carbon (18)

Station Analysis

To perform an analysis of stations in the area, do the following:

  • Design a query to calculate the total number of stations in the dataset.

carbon (19)

  • Design a query to find the most active stations (the stations with the most rows).

    • List the stations and observation counts in descending order.

      carbon (20)

    • Which station id has the highest number of observations?

      carbon (21)

    • Using the most active station id, calculate the lowest, highest, and average temperatures.

      carbon (22)

  • Design a query to retrieve the previous 12 months of temperature observation data (TOBS).

    • Filter by the station with the highest number of observations. Query the previous 12 months of temperature observation data for this station.

      carbon (23)

    • Plot the results as a histogram with bins=12.

      carbon (24) Screen Shot 2023-01-30 at 8 07 00 PM

  • Close out your session.

carbon (25)


Part 2: Design Your Climate App

Now that you have completed your initial analysis, you’ll design a Flask API based on the queries that you have just developed.

Creating the Database connection

carbon (26)

Use Flask to create your routes, as follows:

  • /

    • Homepage.

    • List all available routes. carbon (27)

  • /api/v1.0/precipitation

    • Convert the query results to a dictionary using date as the key and prcp as the value.

    • Return the JSON representation of your dictionary. carbon (28)

  • /api/v1.0/stations

    • Return a JSON list of stations from the dataset. carbon (29)
  • /api/v1.0/tobs

    • Query the dates and temperature observations of the most active station for the previous year of data.

    • Return a JSON list of temperature observations (TOBS) for the previous year. carbon (30)

  • /api/v1.0/<start> and /api/v1.0/<start>/<end>

    • Return a JSON list of the minimum temperature, the average temperature, and the maximum temperature for a given start or start-end range.

    • When given the start only, calculate TMIN, TAVG, and TMAX for all dates greater than or equal to the start date.

    • When given the start and the end date, calculate the TMIN, TAVG, and TMAX for dates from the start date through the end date. carbon (31)

Rubric

Unit 10 Homework Rubric


References

Menne, M.J., I. Durre, R.S. Vose, B.E. Gleason, and T.G. Houston, 2012: An overview of the Global Historical Climatology Network-Daily Database. Journal of Atmospheric and Oceanic Technology, 29, 897-910, https://doi.org/10.1175/JTECH-D-11-00103.1


© 2022 Trilogy Education Services, a 2U, Inc. brand. All Rights Reserved.

About

Connect to SQL DB utilizing SQLAlchemy. Perform an analysis of weather data utilizing Python and Pandas


Languages

Language:Jupyter Notebook 94.5%Language:Python 5.5%