<jupyter_start><jupyter_text>Dependencies<jupyter_code>#import fivethirtyeight style from Matplotlib
from matplotlib import style
style.use('fivethirtyeight')
import matplotlib.pyplot as plt

#import NumPy and Pandas dependencies
import numpy as np
import pandas as pd

#Datetime Dependencies
import datetime as dt

#import a few dependencies from SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import session
from sqlalchemy import create_engine, func
#In order to connect to our SQLite database, we need to use the create_engine() function. 
engine = create_engine("sqlite:///hawaii.sqlite")
Base = automap_base()
#Add the following code to reflect the schema from the tables to our code
Base.prepare(engine, reflect=True)
Base.classes.keys()
#Save References to Each Table
Measurement = Base.classes.measurement
Station = Base.classes.station
from sqlalchemy.orm import Session
session = Session(engine)
#Find the Date One Year Ago
prev_year = dt.date(2017, 8, 23)<jupyter_output><empty_output><jupyter_text>Exploratory Climate Analysis<jupyter_code>#Design a query to retrieve the last 12 months of precipitation data and plot the results 
#Starting from the last data point in the database
#This function allows us to trace back a certain number of days. In this case, we want to go back 365 days.
prev_year = dt.date(2017, 8, 23) - dt.timedelta(days=365)
#precipitation score
results = []
results = session.query(Measurement.date, Measurement.prcp)
print(results.all())
#Perform a query to retrieve the data and precipitation scores 
results = session.query(Measurement.date, Measurement.prcp).filter(Measurement.date >= prev_year).all()
#Save the query results as a Panda dataframe and set the index to the date column 
df = pd.DataFrame(results, columns=['date','precipitation'])
df.set_index(df['date'], inplace=True)
#Sort the dataframe by date 
df = df.sort_index()

#Use Pandas Plotting to plot the data 
df.plot(rot=90)
print(df.to_string(index=False))
df.describe()
session.query()
session.query(func.count(Station.station))
session.query(func.count(Station.station)).all()
session.query(Measurement.station, func.count(Measurement.station))
session.query(Measurement.station, func.count(Measurement.station)).\
	group_by(Measurement.station)
session.query(Measurement.station, func.count(Measurement.station)).\
group_by(Measurement.station).order_by(func.count(Measurement.station).desc())
session.query(Measurement.station, func.count(Measurement.station)).\
group_by(Measurement.station).order_by(func.count(Measurement.station).desc()).all()
session.query()
session.query(func.min(Measurement.tobs), func.max(Measurement.tobs), func.avg(Measurement.tobs))
session.query(func.min(Measurement.tobs), func.max(Measurement.tobs), func.avg(Measurement.tobs)).\
filter(Measurement.station == 'USC00519281')

session.query(func.min(Measurement.tobs), func.max(Measurement.tobs), func.avg(Measurement.tobs)).\
filter(Measurement.station == 'USC00519281').all()
session.query(Measurement.tobs)
results = session.query(Measurement.tobs).\
filter(Measurement.station == 'USC00519281')
results = session.query(Measurement.tobs).\
filter(Measurement.station == 'USC00519281').\
filter(Measurement.date >= prev_year).all()

print(results)
df = pd.DataFrame(results, columns=['tobs'])

import datetime as dt
from pandas.plotting import table

print (df)
df.plot.hist(bins=12)
plt.tight_layout()
#Write a function called 'calc_temps' that will accept start date and end date in the format and return the minimum,average and max temp for that range of datas
def calc_temp(start_date, end_date):
    return session.query(func.min(Measurement.tobs), func.avg(Measurement.tobs), func.max(Measurement.tobs)).\
        filter(Measurement.date >= start_date).filter(Measurement.date <= end_date).all()
print(calc_temp('2012-02-28','2012-03-05'))<jupyter_output>[(62.0, 69.57142857142857, 74.0)]<jupyter_text>Challenge<jupyter_code>#import fivethirtyeight style from Matplotlib
from matplotlib import style
style.use('fivethirtyeight')
import matplotlib.pyplot as plt

#import NumPy and Pandas dependencies
import numpy as np
import pandas as pd

#Datetime Dependencies
import datetime as dt

#import a few dependencies from SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import session
from sqlalchemy import create_engine, func, extract
engine = create_engine("sqlite:///hawaii.sqlite")
Base = automap_base()
#Add the following code to reflect the schema from the tables to our code
Base.prepare(engine, reflect=True)
#Save References to Each Table
Measurement = Base.classes.measurement
Station = Base.classes.station
session = Session(engine)
june_temps = session.query(Measurement).filter(extract('month',Measurement.date)== 6)
june_temps_list = [temp.tobs for temp in june_temps]
print(june_temps_list)
print(np.mean(june_temps_list))
june_df = pd.DataFrame(june_temps_list, columns=["temps"])
june_df.describe()
dec_temps = session.query(Measurement).filter(extract('month',Measurement.date)== 12)
dec_temps_list = [temp.tobs for temp in dec_temps]
print(dec_temps_list)
print(np.mean(dec_temps_list))
dec_df = pd.DataFrame(dec_temps_list, columns=["temps"])
dec_df.describe()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11209495101733233, 'fraction_numerical': 0.018651092690278825, 'mean_word_length': 6.761695906432749, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '291074', 'license': 'MIT', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1678, 'n_words': 438, 'path': 'climate_analysis.ipynb', 'repo_name': 'aindrilachatterjee12345/Climate_analysis-Module9', 'size': '5308'}