{ "cells": [ { "cell_type": "markdown", "id": "8501b536", "metadata": {}, "source": [ "# Timeseries data\n", "\n", "\n", "A timeseries is (unsurprisingly) a series of measurements of the same thing, over time.\n", "\n", "Often the best way to visualize a timeseries is with `sns.lineplot()`, which can be used to plot:\n", "* Timeseries of a single value (such as the temperature on Christmas Day over the years)\n", "* Multiple timeseries in parallel (such as the temperature in each month over the years)\n", "* Timeseries of a summary statistic (such as mean temperature) with errorbars\n" ] }, { "cell_type": "markdown", "id": "06a3540a", "metadata": {}, "source": [ "### Set up Python libraries\n", "\n", "As usual, run the code cell below to import the relevant Python libraries" ] }, { "cell_type": "code", "execution_count": 2, "id": "7f1d34e0", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Set-up Python libraries - you need to run this but you don't need to change it\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import pandas as pd\n", "import seaborn as sns\n", "sns.set_theme(style='white')\n", "import statsmodels.api as sm\n", "import statsmodels.formula.api as smf" ] }, { "cell_type": "markdown", "id": "fb218a2a", "metadata": {}, "source": [ "## Timeseries of a single value\n", "\n", "For example, let's look again at the Oxford weather data:" ] }, { "cell_type": "code", "execution_count": 3, "id": "5b37c633", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | YYYY | \n", "Month | \n", "MM | \n", "DD | \n", "DD365 | \n", "Tmax | \n", "Tmin | \n", "Tmean | \n", "Trange | \n", "Rainfall_mm | \n", "
---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1827 | \n", "Jan | \n", "1 | \n", "1 | \n", "1 | \n", "8.3 | \n", "5.6 | \n", "7.0 | \n", "2.7 | \n", "0.0 | \n", "
1 | \n", "1827 | \n", "Jan | \n", "1 | \n", "2 | \n", "2 | \n", "2.2 | \n", "0.0 | \n", "1.1 | \n", "2.2 | \n", "0.0 | \n", "
2 | \n", "1827 | \n", "Jan | \n", "1 | \n", "3 | \n", "3 | \n", "-2.2 | \n", "-8.3 | \n", "-5.3 | \n", "6.1 | \n", "9.7 | \n", "
3 | \n", "1827 | \n", "Jan | \n", "1 | \n", "4 | \n", "4 | \n", "-1.7 | \n", "-7.8 | \n", "-4.8 | \n", "6.1 | \n", "0.0 | \n", "
4 | \n", "1827 | \n", "Jan | \n", "1 | \n", "5 | \n", "5 | \n", "0.0 | \n", "-10.6 | \n", "-5.3 | \n", "10.6 | \n", "0.0 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
71338 | \n", "2022 | \n", "Apr | \n", "4 | \n", "26 | \n", "116 | \n", "15.2 | \n", "4.1 | \n", "9.7 | \n", "11.1 | \n", "0.0 | \n", "
71339 | \n", "2022 | \n", "Apr | \n", "4 | \n", "27 | \n", "117 | \n", "10.7 | \n", "2.6 | \n", "6.7 | \n", "8.1 | \n", "0.0 | \n", "
71340 | \n", "2022 | \n", "Apr | \n", "4 | \n", "28 | \n", "118 | \n", "12.7 | \n", "3.9 | \n", "8.3 | \n", "8.8 | \n", "0.0 | \n", "
71341 | \n", "2022 | \n", "Apr | \n", "4 | \n", "29 | \n", "119 | \n", "11.7 | \n", "6.7 | \n", "9.2 | \n", "5.0 | \n", "0.0 | \n", "
71342 | \n", "2022 | \n", "Apr | \n", "4 | \n", "30 | \n", "120 | \n", "17.6 | \n", "1.0 | \n", "9.3 | \n", "16.6 | \n", "0.0 | \n", "
71343 rows × 10 columns
\n", "