<jupyter_start><jupyter_text>SQLAlchemy, Sqlite, and Dates  Setup<jupyter_code>import matplotlib
from matplotlib import style
style.use('fivethirtyeight')
import matplotlib.pyplot as plt
import pandas as pd
# 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, inspect, func
engine = create_engine("sqlite:///../Resources/dow.sqlite", echo=False)
engine.execute('SELECT * FROM dow LIMIT 5').fetchall()
inspector = inspect(engine)
columns = inspector.get_columns('dow')
for c in columns:
    print(c['name'], c["type"])<jupyter_output>id INTEGER
quarter INTEGER
stock TEXT
date TEXT
open_price FLOAT
high_price FLOAT
low_price FLOAT
close_price FLOAT
volume INTEGER
percent_change FLOAT<jupyter_text>Reflect and query dates<jupyter_code># Reflect Database into ORM class
Base = automap_base()
Base.prepare(engine, reflect=True)
Dow = Base.classes.dow
session = Session(engine)<jupyter_output><empty_output><jupyter_text>Analysis Analyze the Average prices (open, high, low, close) for all stocks in the Month of May<jupyter_code># Query for the stock and average prices (open, high, low, close) 
# for all stock in the month of May
# Sort the result by stock name

sel = [Dow.stock, 
       func.avg(Dow.open_price), 
       func.avg(Dow.high_price), 
       func.avg(Dow.low_price), 
       func.avg(Dow.close_price)]

# YOUR CODE HERE
# Plot the Results in a Matplotlib bar chart
# YOUR CODE HERE<jupyter_output><empty_output><jupyter_text>BonusCalculate the high-low peak-to-peak (PTP) values for `IBM` stock after `2011-05-31`. * Note: high-low PTP is calculated using `high_price` - `low_price`* Use a DateTime.date object in the query filter* Use a list comprehension or numpy's ravel method to unpack the query's list of tuples into a list of PTP values.* Use matplotlib to plot the PTP values as a boxplot<jupyter_code># Design a query to calculate the PTP for stock `IBM` after May, 2011
# YOUR CODE HERE
ptps
# Load the query into a dataframe, set the index to the date, and plot the ptps
# YOUR CODE HERE<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08398347865993575, 'fraction_numerical': 0.005966039467645709, 'mean_word_length': 5.300578034682081, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '142587', 'license': 'ADSL', 'n_tokens_mistral': 740, 'n_tokens_neox': 694, 'n_words': 249, 'path': '3/Activities/03-Stu_Dates/Unsolved/Stu_Dates.ipynb', 'repo_name': 'Marciooliver/Advanced-Data-Storage-and-Retrieval', 'size': '2179'}