# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Bonus: Temperature Analysis I

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.dtypes

# Set the date column as the DataFrame index
df.set_index(df.date)

# Drop the date column
df.drop(axis=1, columns="date")

# ### Compare June and December data across all years 

from scipy import stats

# Create new column for month
df["month"] = df['date'].map(lambda x: x.strftime("%m"))
df.head()

# Filter data for June
june_data = df.loc[df["month"] == "06"]
june_data

# Return series of unique values for June
june_data['tobs'].value_counts()

# Identify the average temperature for June
june_avg_temp = june_data["tobs"].groupby([june_data["station"]]).mean()
june_avg_temp

# Filter data for Dec
dec_data = df.loc[df["month"] == "12"]
dec_data

# Return series of unique values for Dec
dec_data['tobs'].value_counts()

# Identify the average temperature for December
dec_avg_temp = dec_data["tobs"].groupby([dec_data["station"]]).mean()
dec_avg_temp

# Run paired t-test
stats.ttest_ind(june_avg_temp, dec_avg_temp, equal_var=False)

# ### Analysis

# The pvalue is less than 0.05. The temperature observations between June and December are statistically significant. There is a difference between temperatures for June and December. The means are not equal and used the unpaired t-test. 

StarcoderdataJupyterScriptsDedupFiltered