<jupyter_start><jupyter_text>Activity 5- Plotting Data with Moving AverageFor this exercise we have acquired a dataset of weather information form Austin Texas and will be looking at the changes in average daily temperature.<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Load the dataset into a pandas DataFrame from the csv file<jupyter_code>df = pd.read_csv('austin_weather.csv')
df.head()<jupyter_output><empty_output><jupyter_text>We only need the Date and TempAvgF columns, remove all others from the dataset<jupyter_code>df = df[['Date', 'TempAvgF']]
df.head()<jupyter_output><empty_output><jupyter_text>Initially we are only interested in the first years data, thus we need to extract this information.  Create a column in the DataFrame for the Year value and extract the year value as an integer from the strings in the Date column and assign these values to the Year column.**Note: Temperatures are recorded daily**<jupyter_code>df['Year'] = [int(dt[:4]) for dt in df.Date]
df.head()<jupyter_output><empty_output><jupyter_text>Repeat this process to extract the month values and store the values as integers in a column Month<jupyter_code>df['Month'] = [int(dt[5:7]) for dt in df.Date]
df.head()<jupyter_output><empty_output><jupyter_text>Copy the first year's worth of data to a DataFrame<jupyter_code>df_first_year = df[:365]
df_first_year.head()<jupyter_output><empty_output><jupyter_text>Compute a 20 day moving average filter<jupyter_code>window = 20
rolling = df_first_year.TempAvgF.rolling(window).mean();
rolling.head(n=20)<jupyter_output><empty_output><jupyter_text>Plot the raw data and moving average signal, with the x axis the day number in the year<jupyter_code>fig = plt.figure(figsize=(10, 7))
ax = fig.add_axes([1, 1, 1, 1]);

# Temp measurements
ax.scatter(range(1, 366), df_first_year.TempAvgF, label='Raw Data');
ax.plot(range(1, 366), rolling, c='r', label=f'{window} day moving average');

ax.set_title('Daily Mean Temperature Measurements')
ax.set_xlabel('Day')
ax.set_ylabel('Temperature (degF)')
ax.set_xticks(range(1, 366), 10)
ax.legend();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1070448307410796, 'fraction_numerical': 0.01555352241537054, 'mean_word_length': 7.284090909090909, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '191491', 'license': 'MIT', 'n_tokens_mistral': 760, 'n_tokens_neox': 722, 'n_words': 223, 'path': 'Chapter 3 - Regression Analysis/Activity 5 - Plotting Moving Average (Instructor Version).ipynb', 'repo_name': 'doc-E-brown/Applied-Supervised-Learning-with-Python', 'size': '2186'}