Climate analysis of Hawaii using sqlalchemy to access sqlite and Matplotlib and Pandas and setting up JSON responses via flask
Step 1 - Climate Analysis and Exploration - SQLAlchemy ORM queries, Pandas, and Matplotlib - (Hawaii_climate_analysis.ipynb)
To begin set-up the dependancies required for the task at hand. These are standard libraries used in data analysis:
%matplotlib inline
from matplotlib import style
style.use('fivethirtyeight')
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import datetime as dt
** Python SQL toolkit and Object Relational Mapper **
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, func, inspect, desc
set up engine for sqlite database stored in the Resources folder
engine = create_engine("sqlite:///Resources/hawaii.sqlite",echo=False)
Reflect an existing database into a new model
Base = automap_base()
Reflect the tables
Base.prepare(engine, reflect=True)
Save references to each table in the sqlite DB that we want to access
Meas = Base.classes.measurement
Sta = Base.classes.station
-Precipitation
- Precipitation data for the 12 month period ending 2017-8-23
- Dates and rainfall amounts selected
- The values were sorted by date in a Pandas dataframe
- A plot was created using Matplotlib
- Pandas was used to generate summary statistics
-Weather Stations
- Calculated the total number of stations
- List the stations and observation counts in descending order (tobs)
- Select the most active station in terms of observations made (Waikiki was the result)
- Retrieve the last 12 months of temperature observation data from the most active site
- Plot the results as a histogram with bins=12
Import flask and jsonify libraries
from flask import Flask, jsonify
Set-up Flask to create the APIs for the climate app
app = Flask(__name__)
Setup routes as defined in instructions and return Jsonified data to the user
@app.route("/")
def welcome():
"""List all Available API routes - these routes were defined in the instructions"""
return (
f"Plan your trip to Hawaii using this Climate Analysis API!<br/>\
Note: To look at temps please specify start and end date as yyyy-mm-dd<br/>\
Dates must be between 2010-01-01 and 2017-08-23<br/>\
Query returns Min, Avg, Max <br/>\
<br/>"
f"Available Pages:<br/>"
f"/api/v1.0/precipitation<br/>"
f"/api/v1.0/stations<br/>"
f"/api/v1.0/tobs<br/>"
f"/api/v1.0/temp/start<br/>"
f"/api/v1.0/temp/start/end"
)