{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import plotly.express as px\n", "from scipy import stats" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = {}\n", "\n", "csv_file = \"coal_price_data.csv\"\n", "csv_date = \"date\"\n", "csv_file = csv_file.split(\".\")[0]\n", "df[csv_file] = pd.read_csv(f\"../coal-price-data/{csv_file}.csv\")\n", "df[csv_file][\"datetime\"] = pd.to_datetime(df[csv_file][csv_date], format=\"%b-%y\")\n", "\n", "csv_path = \"../coal-price-data/fred/\"\n", "csv_date = \"DATE\"\n", "csv_date_start = \"2011-11-01\"\n", "csv_date_end = \"2023-12-01\"\n", "csv_list = os.listdir(csv_path)\n", "for csv_file in csv_list:\n", " csv_file = csv_file.split(\".\")[0]\n", " df[csv_file] = pd.read_csv(f\"../coal-price-data/fred/{csv_file}.csv\")\n", " df[csv_file][\"datetime\"] = pd.to_datetime(df[csv_file][csv_date], format=\"%Y-%m-%d\")\n", " df_m2_filtered = df[csv_file].loc[\n", " (df[csv_file][\"datetime\"] >= csv_date_start) & (df[csv_file][\"datetime\"] < csv_date_end)\n", " ]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DATEM2SLdatetime
01959-01-01286.61959-01-01
11959-02-01287.71959-02-01
21959-03-01289.21959-03-01
31959-04-01290.11959-04-01
41959-05-01292.21959-05-01
............
7752023-08-0120825.62023-08-01
7762023-09-0120755.42023-09-01
7772023-10-0120725.72023-10-01
7782023-11-0120767.52023-11-01
7792023-12-0120865.22023-12-01
\n", "

780 rows × 3 columns

\n", "
" ], "text/plain": [ " DATE M2SL datetime\n", "0 1959-01-01 286.6 1959-01-01\n", "1 1959-02-01 287.7 1959-02-01\n", "2 1959-03-01 289.2 1959-03-01\n", "3 1959-04-01 290.1 1959-04-01\n", "4 1959-05-01 292.2 1959-05-01\n", ".. ... ... ...\n", "775 2023-08-01 20825.6 2023-08-01\n", "776 2023-09-01 20755.4 2023-09-01\n", "777 2023-10-01 20725.7 2023-10-01\n", "778 2023-11-01 20767.5 2023-11-01\n", "779 2023-12-01 20865.2 2023-12-01\n", "\n", "[780 rows x 3 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[\"M2SL\"]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "year 2011\n", "date Apr-12\n", "newcastle 48.8\n", "HBA 49.42\n", "ICI_1 52.93\n", "datetime 2011-12-01 00:00:00\n", "dtype: object\n", "year 2023\n", "date Sep-23\n", "newcastle 433.7\n", "HBA 330.97\n", "ICI_1 277.62\n", "datetime 2023-12-01 00:00:00\n", "dtype: object\n", "DATE 1959-01-01\n", "M2SL 286.6\n", "datetime 1959-01-01 00:00:00\n", "dtype: object\n", "DATE 2023-12-01\n", "M2SL 21703.5\n", "datetime 2023-12-01 00:00:00\n", "dtype: object\n" ] } ], "source": [ "print(df[\"coal_price_data\"].min())\n", "print(df[\"coal_price_data\"].max())\n", "print(df[\"M2SL\"].min())\n", "print(df[\"M2SL\"].max())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "datetime=%{x}
newcastle=%{y}", "legendgroup": "", "line": { "color": "#636efa", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "", "orientation": "v", "showlegend": false, "type": "scatter", "x": [ "2023-12-01T00:00:00", "2023-11-01T00:00:00", "2023-10-01T00:00:00", "2023-09-01T00:00:00", "2023-08-01T00:00:00", "2023-07-01T00:00:00", "2023-06-01T00:00:00", "2023-05-01T00:00:00", "2023-04-01T00:00:00", "2023-03-01T00:00:00", "2023-02-01T00:00:00", "2023-01-01T00:00:00", "2022-12-01T00:00:00", "2022-11-01T00:00:00", "2022-10-01T00:00:00", "2022-09-01T00:00:00", "2022-08-01T00:00:00", "2022-07-01T00:00:00", "2022-06-01T00:00:00", "2022-05-01T00:00:00", "2022-04-01T00:00:00", "2022-03-01T00:00:00", "2022-02-01T00:00:00", "2022-01-01T00:00:00", "2021-12-01T00:00:00", "2021-11-01T00:00:00", "2021-10-01T00:00:00", "2021-09-01T00:00:00", "2021-08-01T00:00:00", "2021-07-01T00:00:00", "2021-06-01T00:00:00", "2021-05-01T00:00:00", "2021-04-01T00:00:00", "2021-03-01T00:00:00", "2021-02-01T00:00:00", "2021-01-01T00:00:00", "2020-12-01T00:00:00", "2020-11-01T00:00:00", "2020-10-01T00:00:00", "2020-09-01T00:00:00", "2020-08-01T00:00:00", "2020-07-01T00:00:00", "2020-06-01T00:00:00", "2020-05-01T00:00:00", "2020-04-01T00:00:00", "2020-03-01T00:00:00", "2020-02-01T00:00:00", "2020-01-01T00:00:00", "2019-12-01T00:00:00", "2019-11-01T00:00:00", "2019-10-01T00:00:00", "2019-09-01T00:00:00", "2019-08-01T00:00:00", "2019-07-01T00:00:00", "2019-06-01T00:00:00", "2019-05-01T00:00:00", "2019-04-01T00:00:00", "2019-03-01T00:00:00", "2019-02-01T00:00:00", "2019-01-01T00:00:00", "2018-12-01T00:00:00", "2018-11-01T00:00:00", "2018-10-01T00:00:00", "2018-09-01T00:00:00", "2018-08-01T00:00:00", "2018-07-01T00:00:00", "2018-06-01T00:00:00", "2018-05-01T00:00:00", "2018-04-01T00:00:00", "2018-03-01T00:00:00", "2018-02-01T00:00:00", "2018-01-01T00:00:00", "2017-12-01T00:00:00", "2017-11-01T00:00:00", "2017-10-01T00:00:00", "2017-09-01T00:00:00", "2017-08-01T00:00:00", "2017-07-01T00:00:00", "2017-06-01T00:00:00", "2017-05-01T00:00:00", "2017-04-01T00:00:00", "2017-03-01T00:00:00", "2017-02-01T00:00:00", "2017-01-01T00:00:00", "2016-12-01T00:00:00", "2016-11-01T00:00:00", "2016-10-01T00:00:00", "2016-09-01T00:00:00", "2016-08-01T00:00:00", "2016-07-01T00:00:00", "2016-06-01T00:00:00", "2016-05-01T00:00:00", "2016-04-01T00:00:00", "2016-03-01T00:00:00", "2016-02-01T00:00:00", "2016-01-01T00:00:00", "2015-12-01T00:00:00", "2015-11-01T00:00:00", "2015-10-01T00:00:00", "2015-09-01T00:00:00", "2015-08-01T00:00:00", "2015-07-01T00:00:00", "2015-06-01T00:00:00", "2015-05-01T00:00:00", "2015-04-01T00:00:00", "2015-03-01T00:00:00", "2015-02-01T00:00:00", "2015-01-01T00:00:00", "2014-12-01T00:00:00", "2014-11-01T00:00:00", "2014-10-01T00:00:00", "2014-09-01T00:00:00", "2014-08-01T00:00:00", "2014-07-01T00:00:00", "2014-06-01T00:00:00", "2014-05-01T00:00:00", "2014-04-01T00:00:00", "2014-03-01T00:00:00", "2014-02-01T00:00:00", "2014-01-01T00:00:00", "2013-12-01T00:00:00", "2013-11-01T00:00:00", "2013-10-01T00:00:00", "2013-09-01T00:00:00", "2013-08-01T00:00:00", "2013-07-01T00:00:00", "2013-06-01T00:00:00", "2013-05-01T00:00:00", "2013-04-01T00:00:00", "2013-03-01T00:00:00", "2013-02-01T00:00:00", "2013-01-01T00:00:00", "2012-12-01T00:00:00", "2012-11-01T00:00:00", "2012-10-01T00:00:00", "2012-09-01T00:00:00", "2012-08-01T00:00:00", "2012-07-01T00:00:00", "2012-06-01T00:00:00", "2012-05-01T00:00:00", "2012-04-01T00:00:00", "2012-03-01T00:00:00", "2012-02-01T00:00:00", "2012-01-01T00:00:00", "2011-12-01T00:00:00" ], "xaxis": "x", "y": [ 146.25, 132.15, 121.1, 160.01, 156, 137.3, 128.05, 135, 189.7, 177.25, 192.85, 251.75, 404.15, 398.5, 356.3, 433.7, 425, 407.9, 385.95, 427, 326.6, 259, 274.5, 222.75, 169.6, 152, 223.45, 218, 174.25, 149.75, 134.7, 118.9, 93.3, 96.25, 85.1, 86.2, 80.5, 70.3, 58.2, 58.6, 51.95, 51.95, 52.15, 52, 52.35, 67.85, 67.4, 68.5, 67.7, 67.85, 66.9, 70.05, 65.75, 69.45, 70.9, 83.4, 87.3, 92.75, 96.05, 99, 102.05, 101.7, 105.2, 113.85, 118, 117.55, 114.4, 110.15, 99.4, 96.4, 104.25, 104.35, 100.8, 96.8, 99.9, 97.25, 95.3, 93.2, 81, 73.45, 83.55, 80.75, 83.45, 83, 88.4, 87.45, 108.6, 72.2, 68.75, 61.15, 56.95, 53.5, 50.75, 51.1, 50.5, 48.8, 50.6, 53.55, 53.05, 53.85, 58.5, 60.3, 60.8, 60.05, 62.05, 56.8, 71.05, 62.45, 62.3, 63.45, 64.3, 64.65, 69.25, 68.95, 71.1, 73.9, 73.35, 74.55, 77.55, 82.35, 87.25, 84.55, 84.15, 79.15, 78.55, 77.05, 83, 87.7, 87, 90.65, 94.25, 95.2, 93.75, 85.9, 83.6, 89.5, 91.75, 90.15, 88.4, 91.45, 100.75, 107, 112.1, 117.45, 112.25 ], "yaxis": "y" } ], "layout": { "font": { "size": 18 }, "height": 400, "legend": { "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "rgb(36,36,36)" }, "error_y": { "color": "rgb(36,36,36)" }, "marker": { "line": { "color": "white", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "white", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)" }, "baxis": { "endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "line": { "color": "white", "width": 0.6 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "rgb(237,237,237)" }, "line": { "color": "white" } }, "header": { "fill": { "color": "rgb(217,217,217)" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 1, "tickcolor": "rgb(36,36,36)", "ticks": "outside" } }, "colorscale": { "diverging": [ [ 0, "rgb(103,0,31)" ], [ 0.1, "rgb(178,24,43)" ], [ 0.2, "rgb(214,96,77)" ], [ 0.3, "rgb(244,165,130)" ], [ 0.4, "rgb(253,219,199)" ], [ 0.5, "rgb(247,247,247)" ], [ 0.6, "rgb(209,229,240)" ], [ 0.7, "rgb(146,197,222)" ], [ 0.8, "rgb(67,147,195)" ], [ 0.9, "rgb(33,102,172)" ], [ 1, "rgb(5,48,97)" ] ], "sequential": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ], "sequentialminus": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ] }, "colorway": [ "#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", "#9467BD", "#8C564B", "#E377C2", "#7F7F7F", "#BCBD22", "#17BECF" ], "font": { "color": "rgb(36,36,36)" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "white", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "white", "polar": { "angularaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "bgcolor": "white", "radialaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" } }, "scene": { "xaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "yaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "zaxis": { "backgroundcolor": "white", "gridcolor": "rgb(232,232,232)", "gridwidth": 2, "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zeroline": false, "zerolinecolor": "rgb(36,36,36)" } }, "shapedefaults": { "fillcolor": "black", "line": { "width": 0 }, "opacity": 0.3 }, "ternary": { "aaxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "baxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" }, "bgcolor": "white", "caxis": { "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "title": { "standoff": 15 }, "zeroline": false, "zerolinecolor": "rgb(36,36,36)" }, "yaxis": { "automargin": true, "gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "title": { "standoff": 15 }, "zeroline": false, "zerolinecolor": "rgb(36,36,36)" } } }, "title": { "text": "Coal Price", "x": 0.5 }, "width": 650, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "datetime" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "newcastle" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "y = \"newcastle\"\n", "fig = px.line(df[\"coal_price_data\"], x=\"datetime\", y=y, labels={\"Month\": \"Date\"})\n", "fig.update_layout(\n", " template=\"simple_white\",\n", " font=dict(size=18),\n", " title_text=\"Coal Price\",\n", " width=650,\n", " title_x=0.5,\n", " height=400,\n", ")\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y = \"M2SL\"\n", "fig = px.line(df_m2_filtered, x=\"datetime\", y=y, labels={\"Month\": \"Date\"})\n", "fig.update_layout(\n", " template=\"simple_white\",\n", " font=dict(size=18),\n", " title_text=y,\n", " width=650,\n", " title_x=0.5,\n", " height=400,\n", ")\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_coal" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_m2_filtered" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(len(df_coal.newcastle))\n", "print(len(df_m2_filtered[\"M2SL\"]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = df_coal.newcastle\n", "y = df_coal.ICI_1\n", "\n", "slope, intercept, r, p, std_err = stats.linregress(x, y)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"slope: {slope}\")\n", "print(f\"intercept: {intercept}\")\n", "print(f\"r: {r}\")\n", "print(f\"p: {p}\")\n", "print(f\"std_err: {std_err}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = df_coal.newcastle\n", "y = df_m2_filtered[\"M2SL\"]\n", "\n", "slope, intercept, r, p, std_err = stats.linregress(x, y)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"slope: {slope}\")\n", "print(f\"intercept: {intercept}\")\n", "print(f\"r: {r}\")\n", "print(f\"p: {p}\")\n", "print(f\"std_err: {std_err}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def myfunc(x):\n", " return slope * x + intercept\n", "\n", "\n", "mymodel = list(map(myfunc, x))\n", "\n", "plt.scatter(x, y)\n", "plt.plot(x, mymodel, color=\"orange\")\n", "plt.xlabel(\"Newcastle\")\n", "plt.ylabel(\"ICI 1\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 4 }