{ "cells": [ { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting arviz\n", " Downloading arviz-0.11.2-py3-none-any.whl (1.6 MB)\n", "\u001b[K |████████████████████████████████| 1.6 MB 21.0 MB/s eta 0:00:01\n", "\u001b[?25hCollecting typing-extensions<4,>=3.7.4.3\n", " Downloading typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)\n", "Collecting xarray>=0.16.1\n", " Downloading xarray-0.16.2-py3-none-any.whl (736 kB)\n", "\u001b[K |████████████████████████████████| 736 kB 41.3 MB/s eta 0:00:01\n", "\u001b[?25hCollecting matplotlib>=3.0\n", " Downloading matplotlib-3.3.4-cp36-cp36m-manylinux1_x86_64.whl (11.5 MB)\n", "\u001b[K |████████████████████████████████| 11.5 MB 45.8 MB/s eta 0:00:01\n", "\u001b[?25hCollecting pandas>=0.23\n", " Downloading pandas-1.1.5-cp36-cp36m-manylinux1_x86_64.whl (9.5 MB)\n", "\u001b[K |████████████████████████████████| 9.5 MB 67.4 MB/s eta 0:00:01\n", "\u001b[?25hRequirement already satisfied: setuptools>=38.4 in /opt/conda/lib/python3.6/site-packages (from arviz) (45.2.0.post20200209)\n", "Requirement already satisfied: packaging in /opt/conda/lib/python3.6/site-packages (from arviz) (20.1)\n", "Collecting netcdf4\n", " Downloading netCDF4-1.5.7-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB)\n", "\u001b[K |████████████████████████████████| 4.7 MB 34.4 MB/s eta 0:00:01 |▍ | 51 kB 35.1 MB/s eta 0:00:01\n", "\u001b[?25hRequirement already satisfied: numpy>=1.12 in /opt/conda/lib/python3.6/site-packages (from arviz) (1.15.2)\n", "Requirement already satisfied: scipy>=0.19 in /opt/conda/lib/python3.6/site-packages (from arviz) (1.1.0)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz) (2.4.6)\n", "Requirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz) (7.0.0)\n", "Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz) (0.10.0)\n", "Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz) (2.8.1)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz) (1.1.0)\n", "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.6/site-packages (from pandas>=0.23->arviz) (2019.3)\n", "Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from packaging->arviz) (1.14.0)\n", "Collecting cftime\n", " Downloading cftime-1.5.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (216 kB)\n", "\u001b[K |████████████████████████████████| 216 kB 70.9 MB/s eta 0:00:01\n", "\u001b[31mERROR: pandas 1.1.5 has requirement numpy>=1.15.4, but you'll have numpy 1.15.2 which is incompatible.\u001b[0m\n", "\u001b[?25hInstalling collected packages: typing-extensions, pandas, xarray, matplotlib, cftime, netcdf4, arviz\n", " Attempting uninstall: pandas\n", " Found existing installation: pandas 0.22.0\n", " Uninstalling pandas-0.22.0:\n", " Successfully uninstalled pandas-0.22.0\n", " Attempting uninstall: matplotlib\n", " Found existing installation: matplotlib 2.2.3\n", " Uninstalling matplotlib-2.2.3:\n", " Successfully uninstalled matplotlib-2.2.3\n", "Successfully installed arviz-0.11.2 cftime-1.5.0 matplotlib-3.3.4 netcdf4-1.5.7 pandas-1.1.5 typing-extensions-3.10.0.0 xarray-0.16.2\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install arviz" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting git+https://github.com/pymc-devs/pymc3\n", " Cloning https://github.com/pymc-devs/pymc3 to /tmp/pip-req-build-ygnbehco\n", " Running command git clone -q https://github.com/pymc-devs/pymc3 /tmp/pip-req-build-ygnbehco\n", " Running command git submodule update --init --recursive -q\n", " Installing build dependencies ... \u001b[?25ldone\n", "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n", "\u001b[?25h Preparing wheel metadata ... \u001b[?25ldone\n", "\u001b[31mERROR: Package 'pymc3' requires a different Python: 3.6.4 not in '>=3.7'\u001b[0m\n", "\u001b[?25hNote: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install git+https://github.com/pymc-devs/pymc3" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: bokeh in /opt/conda/lib/python3.6/site-packages (0.12.16)\n", "Requirement already satisfied: six>=1.5.2 in /opt/conda/lib/python3.6/site-packages (from bokeh) (1.14.0)\n", "Requirement already satisfied: PyYAML>=3.10 in /opt/conda/lib/python3.6/site-packages (from bokeh) (5.3)\n", "Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/lib/python3.6/site-packages (from bokeh) (2.8.1)\n", "Requirement already satisfied: Jinja2>=2.7 in /opt/conda/lib/python3.6/site-packages (from bokeh) (2.11.0)\n", "Requirement already satisfied: numpy>=1.7.1 in /opt/conda/lib/python3.6/site-packages (from bokeh) (1.15.2)\n", "Requirement already satisfied: packaging>=16.8 in /opt/conda/lib/python3.6/site-packages (from bokeh) (20.1)\n", "Requirement already satisfied: tornado>=4.3 in /opt/conda/lib/python3.6/site-packages (from bokeh) (6.0.3)\n", "Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/lib/python3.6/site-packages (from Jinja2>=2.7->bokeh) (1.1.1)\n", "Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.6/site-packages (from packaging>=16.8->bokeh) (2.4.6)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install bokeh" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting package metadata (current_repodata.json): - Killed\n", "\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "conda create -n py35 python=3.5 anaconda" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting package metadata (current_repodata.json): \\ Killed\n", "\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "conda install spyder" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# Install library/package\n", "conda install theano" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting package metadata (current_repodata.json): / Killed\n", "\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "conda install tensorflow" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting package metadata (current_repodata.json): | Killed\n", "\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "conda install keras" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting pymc3\n", " Downloading pymc3-3.10.0-py3-none-any.whl (1.9 MB)\n", "\u001b[K |████████████████████████████████| 1.9 MB 13.5 MB/s eta 0:00:01\n", "\u001b[?25hRequirement already satisfied: pandas>=0.18.0 in /opt/conda/lib/python3.6/site-packages (from pymc3) (1.1.5)\n", "Collecting theano-pymc==1.0.11\n", " Downloading Theano-PyMC-1.0.11.tar.gz (2.8 MB)\n", "\u001b[K |████████████████████████████████| 2.8 MB 54.3 MB/s eta 0:00:01\n", "\u001b[?25hCollecting fastprogress>=0.2.0\n", " Downloading fastprogress-1.0.0-py3-none-any.whl (12 kB)\n", "Requirement already satisfied: typing-extensions>=3.7.4 in /opt/conda/lib/python3.6/site-packages (from pymc3) (3.10.0.0)\n", "Requirement already satisfied: dill in /opt/conda/lib/python3.6/site-packages (from pymc3) (0.2.9)\n", "Collecting contextvars; python_version < \"3.7\"\n", " Downloading contextvars-2.4.tar.gz (9.6 kB)\n", "Requirement already satisfied: arviz>=0.9.0 in /opt/conda/lib/python3.6/site-packages (from pymc3) (0.11.2)\n", "Requirement already satisfied: scipy>=0.18.1 in /opt/conda/lib/python3.6/site-packages (from pymc3) (1.1.0)\n", "Requirement already satisfied: numpy>=1.13.0 in /opt/conda/lib/python3.6/site-packages (from pymc3) (1.15.2)\n", "Collecting dataclasses; python_version < \"3.7\"\n", " Downloading dataclasses-0.8-py3-none-any.whl (19 kB)\n", "Requirement already satisfied: patsy>=0.5.1 in /opt/conda/lib/python3.6/site-packages (from pymc3) (0.5.1)\n", "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.6/site-packages (from pandas>=0.18.0->pymc3) (2019.3)\n", "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.6/site-packages (from pandas>=0.18.0->pymc3) (2.8.1)\n", "Collecting immutables>=0.9\n", " Downloading immutables-0.15-cp36-cp36m-manylinux1_x86_64.whl (100 kB)\n", "\u001b[K |████████████████████████████████| 100 kB 19.6 MB/s ta 0:00:01\n", "\u001b[?25hRequirement already satisfied: setuptools>=38.4 in /opt/conda/lib/python3.6/site-packages (from arviz>=0.9.0->pymc3) (45.2.0.post20200209)\n", "Requirement already satisfied: packaging in /opt/conda/lib/python3.6/site-packages (from arviz>=0.9.0->pymc3) (20.1)\n", "Requirement already satisfied: netcdf4 in /opt/conda/lib/python3.6/site-packages (from arviz>=0.9.0->pymc3) (1.5.7)\n", "Requirement already satisfied: matplotlib>=3.0 in /opt/conda/lib/python3.6/site-packages (from arviz>=0.9.0->pymc3) (3.3.4)\n", "Requirement already satisfied: xarray>=0.16.1 in /opt/conda/lib/python3.6/site-packages (from arviz>=0.9.0->pymc3) (0.16.2)\n", "Requirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from patsy>=0.5.1->pymc3) (1.14.0)\n", "Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.6/site-packages (from packaging->arviz>=0.9.0->pymc3) (2.4.6)\n", "Requirement already satisfied: cftime in /opt/conda/lib/python3.6/site-packages (from netcdf4->arviz>=0.9.0->pymc3) (1.5.0)\n", "Requirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz>=0.9.0->pymc3) (7.0.0)\n", "Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz>=0.9.0->pymc3) (0.10.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.0->arviz>=0.9.0->pymc3) (1.1.0)\n", "Building wheels for collected packages: theano-pymc, contextvars\n", " Building wheel for theano-pymc (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for theano-pymc: filename=Theano_PyMC-1.0.11-py3-none-any.whl size=2572022 sha256=90d446d4df3d178ea00a08d0294bf165e0fa75a3412a4f0f1b1053cdd9b5ae59\n", " Stored in directory: /home/jovyan/.cache/pip/wheels/0c/3f/12/4300ed97dce181098755583aea62c4b59f6e5c43fe53a3f097\n", " Building wheel for contextvars (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for contextvars: filename=contextvars-2.4-py3-none-any.whl size=7664 sha256=0b279e2f13ddef2e3289e2b4a86bb76a004675afc18ccb264ccd1e7186d58c23\n", " Stored in directory: /home/jovyan/.cache/pip/wheels/41/11/53/911724983aa48deb94792432e14e518447212dd6c5477d49d3\n", "Successfully built theano-pymc contextvars\n", "Installing collected packages: theano-pymc, fastprogress, immutables, contextvars, dataclasses, pymc3\n", "Successfully installed contextvars-2.4 dataclasses-0.8 fastprogress-1.0.0 immutables-0.15 pymc3-3.10.0 theano-pymc-1.0.11\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install pymc3" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting numpy==1.15.4\n", " Downloading numpy-1.15.4-cp36-cp36m-manylinux1_x86_64.whl (13.9 MB)\n", "\u001b[K |████████████████████████████████| 13.9 MB 24.9 MB/s eta 0:00:01\n", "\u001b[?25hInstalling collected packages: numpy\n", " Attempting uninstall: numpy\n", " Found existing installation: numpy 1.15.2\n", " Uninstalling numpy-1.15.2:\n", " Successfully uninstalled numpy-1.15.2\n", "Successfully installed numpy-1.15.4\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install numpy==1.15.4" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# import library\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 4, "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", " \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", " \n", " \n", " \n", " \n", " \n", "
YrMnDateDateCO2seasonallyfitseasonallyCO2seasonally
0adjustedadjusted fitfilledadjusted filled
1Excel[ppm][ppm][ppm][ppm][ppm][ppm]
2195801212001958.0411-99.99-99.99-99.99-99.99-99.99-99.99
3195802212311958.1260-99.99-99.99-99.99-99.99-99.99-99.99
4195803212591958.2027315.70314.43316.19314.90315.70314.43
.................................
765202108444232021.6219-99.99-99.99-99.99-99.99-99.99-99.99
766202109444542021.7068-99.99-99.99-99.99-99.99-99.99-99.99
767202110444842021.7890-99.99-99.99-99.99-99.99-99.99-99.99
768202111445152021.8740-99.99-99.99-99.99-99.99-99.99-99.99
769202112445452021.9562-99.99-99.99-99.99-99.99-99.99-99.99
\n", "

770 rows × 10 columns

\n", "
" ], "text/plain": [ " Yr Mn Date Date CO2 seasonally fit \\\n", "0 adjusted \n", "1 Excel [ppm] [ppm] [ppm] \n", "2 1958 01 21200 1958.0411 -99.99 -99.99 -99.99 \n", "3 1958 02 21231 1958.1260 -99.99 -99.99 -99.99 \n", "4 1958 03 21259 1958.2027 315.70 314.43 316.19 \n", ".. ... ... ... ... ... ... ... \n", "765 2021 08 44423 2021.6219 -99.99 -99.99 -99.99 \n", "766 2021 09 44454 2021.7068 -99.99 -99.99 -99.99 \n", "767 2021 10 44484 2021.7890 -99.99 -99.99 -99.99 \n", "768 2021 11 44515 2021.8740 -99.99 -99.99 -99.99 \n", "769 2021 12 44545 2021.9562 -99.99 -99.99 -99.99 \n", "\n", " seasonally CO2 seasonally \n", "0 adjusted fit filled adjusted filled \n", "1 [ppm] [ppm] [ppm] \n", "2 -99.99 -99.99 -99.99 \n", "3 -99.99 -99.99 -99.99 \n", "4 314.90 315.70 314.43 \n", ".. ... ... ... \n", "765 -99.99 -99.99 -99.99 \n", "766 -99.99 -99.99 -99.99 \n", "767 -99.99 -99.99 -99.99 \n", "768 -99.99 -99.99 -99.99 \n", "769 -99.99 -99.99 -99.99 \n", "\n", "[770 rows x 10 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# read dataset from URL (July 2021)\n", "data_url = \"https://scrippsco2.ucsd.edu/assets/data/atmospheric/stations/in_situ_co2/monthly/monthly_in_situ_co2_mlo.csv\"\n", "data_monthly= pd.read_csv(data_url,skiprows=54)\n", "data_monthly" ] }, { "cell_type": "code", "execution_count": 5, "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", " \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", " \n", " \n", " \n", " \n", " \n", "
YrMnDateDateCO2seasonallyfitseasonallyCO2seasonally
1Excel[ppm][ppm][ppm][ppm][ppm][ppm]
2195801212001958.0411-99.99-99.99-99.99-99.99-99.99-99.99
3195802212311958.1260-99.99-99.99-99.99-99.99-99.99-99.99
4195803212591958.2027315.70314.43316.19314.90315.70314.43
5195804212901958.2877317.45315.16317.30314.98317.45315.16
.................................
765202108444232021.6219-99.99-99.99-99.99-99.99-99.99-99.99
766202109444542021.7068-99.99-99.99-99.99-99.99-99.99-99.99
767202110444842021.7890-99.99-99.99-99.99-99.99-99.99-99.99
768202111445152021.8740-99.99-99.99-99.99-99.99-99.99-99.99
769202112445452021.9562-99.99-99.99-99.99-99.99-99.99-99.99
\n", "

769 rows × 10 columns

\n", "
" ], "text/plain": [ " Yr Mn Date Date CO2 seasonally fit \\\n", "1 Excel [ppm] [ppm] [ppm] \n", "2 1958 01 21200 1958.0411 -99.99 -99.99 -99.99 \n", "3 1958 02 21231 1958.1260 -99.99 -99.99 -99.99 \n", "4 1958 03 21259 1958.2027 315.70 314.43 316.19 \n", "5 1958 04 21290 1958.2877 317.45 315.16 317.30 \n", ".. ... ... ... ... ... ... ... \n", "765 2021 08 44423 2021.6219 -99.99 -99.99 -99.99 \n", "766 2021 09 44454 2021.7068 -99.99 -99.99 -99.99 \n", "767 2021 10 44484 2021.7890 -99.99 -99.99 -99.99 \n", "768 2021 11 44515 2021.8740 -99.99 -99.99 -99.99 \n", "769 2021 12 44545 2021.9562 -99.99 -99.99 -99.99 \n", "\n", " seasonally CO2 seasonally \n", "1 [ppm] [ppm] [ppm] \n", "2 -99.99 -99.99 -99.99 \n", "3 -99.99 -99.99 -99.99 \n", "4 314.90 315.70 314.43 \n", "5 314.98 317.45 315.16 \n", ".. ... ... ... \n", "765 -99.99 -99.99 -99.99 \n", "766 -99.99 -99.99 -99.99 \n", "767 -99.99 -99.99 -99.99 \n", "768 -99.99 -99.99 -99.99 \n", "769 -99.99 -99.99 -99.99 \n", "\n", "[769 rows x 10 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Delete row 1: first two lines : \" \" and “Excel”. These lines seems to be useless.\n", "data_monthly = data_monthly.iloc[1:]\n", "data_monthly" ] }, { "cell_type": "code", "execution_count": 21, "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", " \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", " \n", " \n", " \n", " \n", " \n", "
YrMnDateDateCO2seasonallyfitseasonallyCO2seasonally
3195802212311958.1260-99.99-99.99-99.99-99.99-99.99-99.99
4195803212591958.2027315.70314.43316.19314.90315.70314.43
5195804212901958.2877317.45315.16317.30314.98317.45315.16
6195805213201958.3699317.51314.71317.86315.06317.51314.71
7195806213511958.4548-99.99-99.99317.24315.14317.24315.14
.................................
765202108444232021.6219-99.99-99.99-99.99-99.99-99.99-99.99
766202109444542021.7068-99.99-99.99-99.99-99.99-99.99-99.99
767202110444842021.7890-99.99-99.99-99.99-99.99-99.99-99.99
768202111445152021.8740-99.99-99.99-99.99-99.99-99.99-99.99
769202112445452021.9562-99.99-99.99-99.99-99.99-99.99-99.99
\n", "

767 rows × 10 columns

\n", "
" ], "text/plain": [ " Yr Mn Date Date CO2 seasonally fit \\\n", "3 1958 02 21231 1958.1260 -99.99 -99.99 -99.99 \n", "4 1958 03 21259 1958.2027 315.70 314.43 316.19 \n", "5 1958 04 21290 1958.2877 317.45 315.16 317.30 \n", "6 1958 05 21320 1958.3699 317.51 314.71 317.86 \n", "7 1958 06 21351 1958.4548 -99.99 -99.99 317.24 \n", ".. ... ... ... ... ... ... ... \n", "765 2021 08 44423 2021.6219 -99.99 -99.99 -99.99 \n", "766 2021 09 44454 2021.7068 -99.99 -99.99 -99.99 \n", "767 2021 10 44484 2021.7890 -99.99 -99.99 -99.99 \n", "768 2021 11 44515 2021.8740 -99.99 -99.99 -99.99 \n", "769 2021 12 44545 2021.9562 -99.99 -99.99 -99.99 \n", "\n", " seasonally CO2 seasonally \n", "3 -99.99 -99.99 -99.99 \n", "4 314.90 315.70 314.43 \n", "5 314.98 317.45 315.16 \n", "6 315.06 317.51 314.71 \n", "7 315.14 317.24 315.14 \n", ".. ... ... ... \n", "765 -99.99 -99.99 -99.99 \n", "766 -99.99 -99.99 -99.99 \n", "767 -99.99 -99.99 -99.99 \n", "768 -99.99 -99.99 -99.99 \n", "769 -99.99 -99.99 -99.99 \n", "\n", "[767 rows x 10 columns]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Delete row 1: first two lines : \" \" and “Excel”. These lines seems to be useless.\n", "data = data_monthly.iloc[1:]\n", "data" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "# replace '-99.99' values with 'nan'\n", "from numpy import nan\n", "data.replace(to_replace=-99.99, value=np.nan, inplace=True)\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "# fix column names\n", "cols = [\n", " \"year\",\n", " \"month\",\n", " \"--\",\n", " \"--\",\n", " \"CO2\",\n", " \"seasonaly_adjusted\",\n", " \"fit\",\n", " \"seasonally_adjusted_fit\",\n", " \"CO2_filled\",\n", " \"seasonally_adjusted_filled\",\n", "]\n", "data.columns = cols\n", "cols.remove(\"--\")\n", "cols.remove(\"--\")\n", "data= data[cols]\n" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:5: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " \"\"\"\n" ] } ], "source": [ "# drop rows with nan\n", "import numpy as np\n", "import pandas as pd\n", "data.dropna()\n", "data.dropna(inplace=True)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " \n" ] }, { "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", "
CO2seasonaly_adjustedfitseasonally_adjusted_fitCO2_filledseasonally_adjusted_filled
1958-02-15-99.99-99.99-99.99-99.99-99.99-99.99
1958-03-15315.70314.43316.19314.90315.70314.43
1958-04-15317.45315.16317.30314.98317.45315.16
1958-05-15317.51314.71317.86315.06317.51314.71
1958-06-15-99.99-99.99317.24315.14317.24315.14
\n", "
" ], "text/plain": [ " CO2 seasonaly_adjusted fit seasonally_adjusted_fit \\\n", "1958-02-15 -99.99 -99.99 -99.99 -99.99 \n", "1958-03-15 315.70 314.43 316.19 314.90 \n", "1958-04-15 317.45 315.16 317.30 314.98 \n", "1958-05-15 317.51 314.71 317.86 315.06 \n", "1958-06-15 -99.99 -99.99 317.24 315.14 \n", "\n", " CO2_filled seasonally_adjusted_filled \n", "1958-02-15 -99.99 -99.99 \n", "1958-03-15 315.70 314.43 \n", "1958-04-15 317.45 315.16 \n", "1958-05-15 317.51 314.71 \n", "1958-06-15 317.24 315.14 " ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# fix time index\n", "data[\"day\"] = 15\n", "data.index = pd.to_datetime(data[[\"year\", \"month\", \"day\"]])\n", "cols.remove(\"year\")\n", "cols.remove(\"month\")\n", "data = data[cols]\n", "\n", "data.head(5)" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "# function to convert datetimes to numbers that are useful to algorithms\n", "# this will be useful later when doing prediction\n", "\n", "def dates_to_idx(timelist):\n", " reference_time = pd.to_datetime(\"1958-03-15\")\n", " t = (timelist - reference_time) / pd.Timedelta(365, \"D\")\n", " return np.asarray(t)\n", "\n", "\n", "t = dates_to_idx(data.index)\n", "\n" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "# split into training and test set\n", "sep_idx = data.index.searchsorted(pd.to_datetime(\"2003-12-15\"))\n", "data_early = data.iloc[: sep_idx + 1, :]\n", "data_later = data.iloc[sep_idx:, :]" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [], "source": [ "# make plot\n", "#import matplotlib.pyplot as plt\n", "from bokeh.plotting import figure, show\n", "from bokeh.models import BoxAnnotation, Label, Legend, Span\n", "from bokeh.io import output_notebook\n", "from bokeh.palettes import brewer\n", "\n", "p = figure(\n", " x_axis_type=\"datetime\",\n", " title=\"Monthly CO2 Readings from Mauna Loa (1958-2021)\",\n", " plot_width=550,\n", " plot_height=350,\n", ")\n", "p.yaxis.axis_label = \"CO2 [ppm]\"\n", "p.xaxis.axis_label = \"Date\"\n", "predict_region = BoxAnnotation(\n", " left=pd.to_datetime(\"2003-12-15\"), fill_alpha=0.1, fill_color=\"firebrick\"\n", ")\n", "p.add_layout(predict_region)\n", "ppm400 = Span(location=400, dimension=\"width\", line_color=\"red\", line_dash=\"dashed\", line_width=2)\n", "p.add_layout(ppm400)\n", "\n", "p.line(data.index, data[\"CO2\"], line_width=2, line_color=\"black\", alpha=0.5)\n", "p.circle(data.index, data[\"CO2\"], line_color=\"black\", alpha=0.1, size=2)\n", "\n", "train_label = Label(\n", " x=100,\n", " y=165,\n", " x_units=\"screen\",\n", " y_units=\"screen\",\n", " text=\"Training Set\",\n", " render_mode=\"css\",\n", " border_line_alpha=0.0,\n", " background_fill_alpha=0.0,\n", ")\n", "test_label = Label(\n", " x=585,\n", " y=80,\n", " x_units=\"screen\",\n", " y_units=\"screen\",\n", " text=\"Test Set\",\n", " render_mode=\"css\",\n", " border_line_alpha=0.0,\n", " background_fill_alpha=0.0,\n", ")\n", "\n", "p.add_layout(train_label)\n", "p.add_layout(test_label)\n", "show(p)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting package metadata (current_repodata.json): - Killed\n", "\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "conda install mkl-service" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[31mERROR: Could not find a version that satisfies the requirement pymc3==3.11.2 (from versions: 3.0rc1, 3.0rc2, 3.0rc4, 3.0rc5, 3.0rc6, 3.0, 3.1rc1, 3.1rc2, 3.1rc3, 3.1, 3.2rc1, 3.2, 3.3rc1, 3.3rc2, 3.3, 3.4rc1, 3.4rc2, 3.4.1, 3.5rc1, 3.5, 3.6, 3.7rc1, 3.7, 3.8, 3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.10.0)\u001b[0m\n", "\u001b[31mERROR: No matching distribution found for pymc3==3.11.2\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "# Install library/package\n", "pip install pymc3==3.11.2" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "module 'arviz' has no attribute 'geweke'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpymc3\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0marviz\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0maz\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pymc3/__init__.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0msampling\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0msmc\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mstats\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 65\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mstep_methods\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mtests\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtest\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.6/site-packages/pymc3/stats/__init__.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0mcompare\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmap_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompare\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0mess\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmap_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mess\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0mgeweke\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmap_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeweke\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0mhpd\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmap_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhpd\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0mloo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmap_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloo\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: module 'arviz' has no attribute 'geweke'" ] } ], "source": [ "# make plot\n", "\n", "import pymc3 as pm\n", "import arviz as az\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "x = np.linspace(0, 150, 5000)\n", "priors = [\n", " (\"ℓ_pdecay\", pm.Gamma.dist(alpha=10, beta=0.075)),\n", " (\"ℓ_psmooth\", pm.Gamma.dist(alpha=4, beta=3)),\n", " (\"period\", pm.Normal.dist(mu=1.0, sigma=0.05)),\n", " (\"ℓ_med\", pm.Gamma.dist(alpha=2, beta=0.75)),\n", " (\"α\", pm.Gamma.dist(alpha=5, beta=2)),\n", " (\"ℓ_trend\", pm.Gamma.dist(alpha=4, beta=0.1)),\n", " (\"ℓ_noise\", pm.Gamma.dist(alpha=2, beta=4)),\n", "]\n", "\n", "colors = brewer[\"Paired\"][7]\n", "\n", "p = figure(\n", " title=\"Lengthscale and period priors\",\n", " plot_width=550,\n", " plot_height=350,\n", " x_range=(-1, 8),\n", " y_range=(0, 2),\n", ")\n", "p.yaxis.axis_label = \"Probability\"\n", "p.xaxis.axis_label = \"Years\"\n", "\n", "for i, prior in enumerate(priors):\n", " p.line(\n", " x,\n", " np.exp(prior[1].logp(x).eval()),\n", " legend_label=prior[0],\n", " line_width=3,\n", " line_color=colors[i],\n", " )\n", "show(p)" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "mkdir data-visualization\n" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/jovyan/work/module3/exo3/data-visualization\n" ] } ], "source": [ "cd data-visualization\n" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting plotnine\n", " Downloading plotnine-0.8.0-py3-none-any.whl (4.7 MB)\n", "\u001b[K |████████████████████████████████| 4.7 MB 16.0 MB/s eta 0:00:01\n", "\u001b[?25hCollecting descartes>=1.1.0\n", " Downloading descartes-1.1.0-py3-none-any.whl (5.8 kB)\n", "Collecting mizani>=0.7.3\n", " Downloading mizani-0.7.3-py3-none-any.whl (63 kB)\n", "\u001b[K |████████████████████████████████| 63 kB 4.5 MB/s eta 0:00:01\n", "\u001b[?25hCollecting scipy>=1.5.0\n", " Downloading scipy-1.5.4-cp36-cp36m-manylinux1_x86_64.whl (25.9 MB)\n", "\u001b[K |████████████████████████████████| 25.9 MB 54.9 MB/s eta 0:00:01 |██████████████████████▋ | 18.3 MB 54.9 MB/s eta 0:00:01\n", "\u001b[?25hCollecting numpy>=1.19.0\n", " Downloading numpy-1.19.5-cp36-cp36m-manylinux2010_x86_64.whl (14.8 MB)\n", "\u001b[K |████████████████████████████████| 14.8 MB 14.5 MB/s eta 0:00:01 |██████████████████████▋ | 10.5 MB 14.5 MB/s eta 0:00:01\n", "\u001b[?25hRequirement already satisfied: patsy>=0.5.1 in /opt/conda/lib/python3.6/site-packages (from plotnine) (0.5.1)\n", "Requirement already satisfied: matplotlib>=3.1.1 in /opt/conda/lib/python3.6/site-packages (from plotnine) (3.3.4)\n", "Requirement already satisfied: pandas>=1.1.0 in /opt/conda/lib/python3.6/site-packages (from plotnine) (1.1.5)\n", "Collecting statsmodels>=0.12.1\n", " Downloading statsmodels-0.12.2-cp36-cp36m-manylinux1_x86_64.whl (9.5 MB)\n", "\u001b[K |████████████████████████████████| 9.5 MB 49.3 MB/s eta 0:00:01\n", "\u001b[?25hCollecting palettable\n", " Downloading palettable-3.3.0-py2.py3-none-any.whl (111 kB)\n", "\u001b[K |████████████████████████████████| 111 kB 65.3 MB/s eta 0:00:01\n", "\u001b[?25hRequirement already satisfied: six in /opt/conda/lib/python3.6/site-packages (from patsy>=0.5.1->plotnine) (1.14.0)\n", "Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (0.10.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (1.1.0)\n", "Requirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (7.0.0)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (2.4.6)\n", "Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (2.8.1)\n", "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.6/site-packages (from pandas>=1.1.0->plotnine) (2019.3)\n", "Requirement already satisfied: setuptools in /opt/conda/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib>=3.1.1->plotnine) (45.2.0.post20200209)\n", "Installing collected packages: descartes, palettable, numpy, mizani, scipy, statsmodels, plotnine\n", " Attempting uninstall: numpy\n", " Found existing installation: numpy 1.15.4\n", " Uninstalling numpy-1.15.4:\n", " Successfully uninstalled numpy-1.15.4\n", " Attempting uninstall: scipy\n", " Found existing installation: scipy 1.1.0\n", " Uninstalling scipy-1.1.0:\n", " Successfully uninstalled scipy-1.1.0\n", " Attempting uninstall: statsmodels\n", " Found existing installation: statsmodels 0.9.0\n", " Uninstalling statsmodels-0.9.0:\n", " Successfully uninstalled statsmodels-0.9.0\n", "Successfully installed descartes-1.1.0 mizani-0.7.3 numpy-1.19.5 palettable-3.3.0 plotnine-0.8.0 scipy-1.5.4 statsmodels-0.12.2\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install plotnine" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (1.1.5)\n", "Requirement already satisfied: plotnine in /opt/conda/lib/python3.6/site-packages (0.8.0)\n", "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.6/site-packages (from pandas) (2019.3)\n", "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.6/site-packages (from pandas) (2.8.1)\n", "Requirement already satisfied: numpy>=1.15.4 in /opt/conda/lib/python3.6/site-packages (from pandas) (1.19.5)\n", "Requirement already satisfied: mizani>=0.7.3 in /opt/conda/lib/python3.6/site-packages (from plotnine) (0.7.3)\n", "Requirement already satisfied: matplotlib>=3.1.1 in /opt/conda/lib/python3.6/site-packages (from plotnine) (3.3.4)\n", "Requirement already satisfied: patsy>=0.5.1 in /opt/conda/lib/python3.6/site-packages (from plotnine) (0.5.1)\n", "Requirement already satisfied: scipy>=1.5.0 in /opt/conda/lib/python3.6/site-packages (from plotnine) (1.5.4)\n", "Requirement already satisfied: statsmodels>=0.12.1 in /opt/conda/lib/python3.6/site-packages (from plotnine) (0.12.2)\n", "Requirement already satisfied: descartes>=1.1.0 in /opt/conda/lib/python3.6/site-packages (from plotnine) (1.1.0)\n", "Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.6/site-packages (from python-dateutil>=2.7.3->pandas) (1.14.0)\n", "Requirement already satisfied: palettable in /opt/conda/lib/python3.6/site-packages (from mizani>=0.7.3->plotnine) (3.3.0)\n", "Requirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (7.0.0)\n", "Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (0.10.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (1.1.0)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/conda/lib/python3.6/site-packages (from matplotlib>=3.1.1->plotnine) (2.4.6)\n", "Requirement already satisfied: setuptools in /opt/conda/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib>=3.1.1->plotnine) (45.2.0.post20200209)\n" ] } ], "source": [ "!pip install pandas plotnine" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# make plot using ggplot\n", "\n", "%matplotlib inline\n", "from plotnine.data import mpg\n", "from plotnine import ggplot\n", "from plotnine import ggplot, aes, labs\n", "mpg = ggplot(data = data, aes(x = datetime, y = CO2)),\n", " labs(title = \"Evolution of CO2 concentration in Hawaii\",\n", " subtitle = \"(1958-2020)\",\n", " caption = \"Datafrom Scripps CO2 Program\",\n", " tag = \"Figure 1\",\n", " x = \"Date\",\n", " y = \"CO2 Concentration (ppm)\") + theme_bw() + geom_point(size = 0.5, color = \"grey50\")\n", "\n", "ggplot(mpg)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }