<jupyter_start><jupyter_text>Bonus: Temperature Analysis I<jupyter_code>import pandas as pd
from datetime import datetime as dt
# "tobs" is "temperature observations"
df = pd.read_csv('Resources/hawaii_measurements.csv')
df.head()
# Convert the date column format from string to datetime
df['date'] = pd.to_datetime(df['date'])
df.head()
# Set the date column as the DataFrame index
df = df.set_index("date")
df
# Drop the date column
df_dateless = df.reset_index()
df_dateless = df_dateless.drop(columns=['date'])
df_dateless<jupyter_output><empty_output><jupyter_text>Compare June and December data across all years<jupyter_code>from scipy import stats
# Filter data for desired months
june_df = df.filter(regex="\d\d\d\d-06-\d\d", axis=0).sort_index()
june_df
def get_years(data):
    min_date = min(data.index)
    max_date = max(data.index)
    return list(range(min_date.year, max_date.year))
# Identify the average temperature for June
june_data = {}
for year in get_years(june_df):
    key = str(year)
    value = june_df.filter(regex = f"{year}-\d\d-", axis=0)["tobs"]
    june_data[key] = value
    print(f"year: {year}, avg temp: {round(value.mean(), 2)}")
# Identify the average temperature for December
december_df = df.filter(regex="\d\d\d\d-12-\d\d", axis=0).sort_index()
december_data = {}
for year in get_years(december_df):
    key = str(year)
    value = december_df.filter(regex = f"{year}-\d\d-", axis=0)["tobs"]
    june_data[key] = value
    print(f"year: {year}, avg temp: {round(value.mean(), 2)}")
# Run paired t-test
t_value, p_value = stats.ttest_ind(june_df["tobs"], december_df["tobs"])
print(f"t-value: {t_value}")
print(f"p-value: {p_value}")<jupyter_output>t-value: 31.60372399000329
p-value: 3.9025129038616655e-191<jupyter_text>Analysis<jupyter_code>import matplotlib.pyplot as plt 
import matplotlib.ticker as tick
years = get_years(june_df)
fig, ax = plt.subplots(1, 1)
plt.boxplot(
    [june_df.filter(regex = f"{year}-\d\d-", axis=0)["tobs"]
    for year in years], 
    vert=True, 
    labels=years)
ax.yaxis.set_major_formatter(tick.StrMethodFormatter('{x:,.0f}°')) 
plt.title(f'Hawaii Temperature Observations for June')
plt.xlabel('Years')
plt.ylabel('Temperature (°F)')
plt.grid(alpha = 0.4)
plt.savefig('Images/june_temp.png')
plt.show()
years = get_years(december_df)
fig, ax = plt.subplots(1, 1)
plt.boxplot(
    [december_df.filter(regex = f"{year}-\d\d-", axis=0)["tobs"]
    for year in years], 
    vert=True, 
    labels=years)
ax.yaxis.set_major_formatter(tick.StrMethodFormatter('{x:,.0f}°')) 
plt.title(f'Hawaii Temperature Observations for December')
plt.xlabel('Years')
plt.ylabel('Temperature (°F)')
plt.grid(alpha = 0.4)
plt.savefig('Images/june_temp.png')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16110304789550073, 'fraction_numerical': 0.02104499274310595, 'mean_word_length': 5.426573426573427, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '650316', 'license': 'ADSL', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1067, 'n_words': 212, 'path': 'temp_analysis_bonus_1_starter.ipynb', 'repo_name': 'ianmkinney/sqlalchemy-challenge', 'size': '2756'}