{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "taruma-hidrokit-prep-read", "version": "0.3.2", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "DNoXJIBlc6xx", "colab_type": "text" }, "source": [ "# Penggunaan `hidrokit.prep.read`\n", "\n", "- Kategori: _data preparation_\n", "- Tujuan: Membaca informasi dari tabel\n", "- Dokumentasi: [readthedocs](https://hidrokit.readthedocs.io/en/stable/prep.html#module-prep.read)\n", "\n", "## Informasi notebook\n", "\n", "- __notebook name__: `taruma_hidrokit_prep_read`\n", "- __notebook version/date__: `1.0.1`/`20190713`\n", "- __notebook server__: Google Colab\n", "- __hidrokit version__: `0.2.0`\n", "- __python version__: `3.7`" ] }, { "cell_type": "markdown", "metadata": { "id": "TD78GcYGft9Y", "colab_type": "text" }, "source": [ "## Instalasi hidrokit" ] }, { "cell_type": "code", "metadata": { "id": "YY4tPDgYc3cG", "colab_type": "code", "outputId": "2bad7456-acfa-49b7-de46-2daf1151eb64", "colab": { "base_uri": "https://localhost:8080/", "height": 255 } }, "source": [ "### Instalasi melalui PyPI\n", "!pip install hidrokit\n", "\n", "### Instalasi melalui Github\n", "# !pip install git+https://github.com/taruma/hidrokit.git\n", "\n", "### Instalasi melalui Github (Latest)\n", "# !pip install git+https://github.com/taruma/hidrokit.git@latest" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Collecting hidrokit\n", " Downloading https://files.pythonhosted.org/packages/43/9d/343d2a413a07463a21dd13369e31d664d6733bbfd46276abef5d804c83d1/hidrokit-0.2.0-py2.py3-none-any.whl\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from hidrokit) (1.16.4)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from hidrokit) (0.24.2)\n", "Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from hidrokit) (3.0.3)\n", "Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python3.6/dist-packages (from pandas->hidrokit) (2.5.3)\n", "Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas->hidrokit) (2018.9)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (0.10.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (1.1.0)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (2.4.0)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.5.0->pandas->hidrokit) (1.12.0)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib->hidrokit) (41.0.1)\n", "Installing collected packages: hidrokit\n", "Successfully installed hidrokit-0.2.0\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "dkMQjx0tgf7o", "colab_type": "text" }, "source": [ "## _Import Library_" ] }, { "cell_type": "code", "metadata": { "id": "P6czxsUrgkR8", "colab_type": "code", "colab": {} }, "source": [ "import numpy as np\n", "import pandas as pd" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "l9Lyn6MdgWgY", "colab_type": "text" }, "source": [ "## Dataset\n", "\n", "Digunakan dataset buatan menggunakan numpy.random" ] }, { "cell_type": "code", "metadata": { "id": "fwIt_oU5gB4w", "colab_type": "code", "outputId": "dd1372f4-aedf-4c3c-b001-4fd95fdbdbbb", "colab": { "base_uri": "https://localhost:8080/", "height": 136 } }, "source": [ "# Buat dataset sebanyak satu tahun (tahun 2001)\n", "date_index = pd.date_range('20010101', '20011231')\n", "\n", "# Generate random data\n", "np.random.seed(1234)\n", "data = np.random.rand(len(date_index), 6) * 100\n", "data[data < 30] = np.nan\n", "data = data.round()\n", "data" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "array([[nan, 62., 44., 79., 78., nan],\n", " [nan, 80., 96., 88., 36., 50.],\n", " [68., 71., 37., 56., 50., nan],\n", " ...,\n", " [37., nan, 77., 93., 42., 52.],\n", " [nan, 43., nan, 48., 50., 49.],\n", " [79., nan, 72., 55., 34., 94.]])" ] }, "metadata": { "tags": [] }, "execution_count": 3 } ] }, { "cell_type": "code", "metadata": { "id": "omeOgVOHgBzY", "colab_type": "code", "outputId": "69b6d22b-a4f5-4823-f9d2-72f4d15b88d3", "colab": { "base_uri": "https://localhost:8080/", "height": 359 } }, "source": [ "# Ubah ke bentuk dataframe\n", "dataset = pd.DataFrame(\n", " data=data,\n", " columns='sta_A sta_B sta_C sta_D sta_E sta_F'.split(),\n", " index=date_index\n", ")\n", "dataset.head(10)" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "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", "
sta_Asta_Bsta_Csta_Dsta_Esta_F
2001-01-01NaN62.044.079.078.0NaN
2001-01-02NaN80.096.088.036.050.0
2001-01-0368.071.037.056.050.0NaN
2001-01-0477.088.036.062.0NaN37.0
2001-01-0593.065.040.079.032.057.0
2001-01-0687.044.080.0NaN70.070.0
2001-01-07NaN92.044.091.0NaNNaN
2001-01-08NaN67.059.053.0NaN56.0
2001-01-0933.050.0NaN61.057.0NaN
2001-01-1062.091.079.099.096.079.0
\n", "
" ], "text/plain": [ " sta_A sta_B sta_C sta_D sta_E sta_F\n", "2001-01-01 NaN 62.0 44.0 79.0 78.0 NaN\n", "2001-01-02 NaN 80.0 96.0 88.0 36.0 50.0\n", "2001-01-03 68.0 71.0 37.0 56.0 50.0 NaN\n", "2001-01-04 77.0 88.0 36.0 62.0 NaN 37.0\n", "2001-01-05 93.0 65.0 40.0 79.0 32.0 57.0\n", "2001-01-06 87.0 44.0 80.0 NaN 70.0 70.0\n", "2001-01-07 NaN 92.0 44.0 91.0 NaN NaN\n", "2001-01-08 NaN 67.0 59.0 53.0 NaN 56.0\n", "2001-01-09 33.0 50.0 NaN 61.0 57.0 NaN\n", "2001-01-10 62.0 91.0 79.0 99.0 96.0 79.0" ] }, "metadata": { "tags": [] }, "execution_count": 4 } ] }, { "cell_type": "markdown", "metadata": { "id": "xWA7zXBDkSZc", "colab_type": "text" }, "source": [ "# Fungsi `.missing_row()`\n", "\n", "**Tujuan**: Memperoleh informasi index data yang hilang\n", "\n", "**Sintaks**: `prep.read.missing_row(dataframe, date_index=True, date_format='%Y/%m/%d')`\n", "\n", "**Return**: `dictionary`\n", "\n", "**Dokumentasi**: [readthedocs](https://hidrokit.readthedocs.io/en/stable/prep.html#prep.read.missing_row)" ] }, { "cell_type": "markdown", "metadata": { "id": "gz2AxCR2n7VB", "colab_type": "text" }, "source": [ "### Fungsi dasar" ] }, { "cell_type": "code", "metadata": { "id": "FVuf44Hjkxfn", "colab_type": "code", "colab": {} }, "source": [ "# Import module\n", "from hidrokit.prep import read" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "4D8sZ7_3k7IU", "colab_type": "code", "outputId": "7a9cc219-7188-4666-c39a-65a34d4aee72", "colab": { "base_uri": "https://localhost:8080/", "height": 359 } }, "source": [ "# Menampilkan dataset\n", "dataset.head(10)" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "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", "
sta_Asta_Bsta_Csta_Dsta_Esta_F
2001-01-01NaN62.044.079.078.0NaN
2001-01-02NaN80.096.088.036.050.0
2001-01-0368.071.037.056.050.0NaN
2001-01-0477.088.036.062.0NaN37.0
2001-01-0593.065.040.079.032.057.0
2001-01-0687.044.080.0NaN70.070.0
2001-01-07NaN92.044.091.0NaNNaN
2001-01-08NaN67.059.053.0NaN56.0
2001-01-0933.050.0NaN61.057.0NaN
2001-01-1062.091.079.099.096.079.0
\n", "
" ], "text/plain": [ " sta_A sta_B sta_C sta_D sta_E sta_F\n", "2001-01-01 NaN 62.0 44.0 79.0 78.0 NaN\n", "2001-01-02 NaN 80.0 96.0 88.0 36.0 50.0\n", "2001-01-03 68.0 71.0 37.0 56.0 50.0 NaN\n", "2001-01-04 77.0 88.0 36.0 62.0 NaN 37.0\n", "2001-01-05 93.0 65.0 40.0 79.0 32.0 57.0\n", "2001-01-06 87.0 44.0 80.0 NaN 70.0 70.0\n", "2001-01-07 NaN 92.0 44.0 91.0 NaN NaN\n", "2001-01-08 NaN 67.0 59.0 53.0 NaN 56.0\n", "2001-01-09 33.0 50.0 NaN 61.0 57.0 NaN\n", "2001-01-10 62.0 91.0 79.0 99.0 96.0 79.0" ] }, "metadata": { "tags": [] }, "execution_count": 6 } ] }, { "cell_type": "markdown", "metadata": { "id": "wiTiL2AqlW-k", "colab_type": "text" }, "source": [ "Dari dataset diatas, ingin diperoleh informasi pada tanggal berapa saja data yang hilang. \n", "\n", "Contoh: Pada stasiun A saya ingin memperoleh daftar tanggal yang mengalami kehilangan data. Dari tabel diatas terlihat pada bulan januari tanggal 1, 2, 7, dan 8 mengalami kehilangan data. " ] }, { "cell_type": "code", "metadata": { "id": "Y4CQqnRClTU4", "colab_type": "code", "outputId": "0ec116f9-0ff3-4f2f-b4fb-d06328edb2c5", "colab": { "base_uri": "https://localhost:8080/", "height": 54 } }, "source": [ "# Menggunakan module read\n", "data_hilang = read.missing_row(dataset)\n", "print(data_hilang)" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "{'sta_A': ['2001/01/01', '2001/01/02', '2001/01/07', '2001/01/08', '2001/01/11', '2001/01/14', '2001/01/16', '2001/01/19', '2001/01/25', '2001/01/30', '2001/02/02', '2001/02/05', '2001/02/08', '2001/02/10', '2001/02/11', '2001/02/20', '2001/02/21', '2001/02/22', '2001/02/25', '2001/02/28', '2001/03/01', '2001/03/03', '2001/03/04', '2001/03/06', '2001/03/09', '2001/03/11', '2001/03/13', '2001/03/18', '2001/03/22', '2001/03/25', '2001/03/26', '2001/03/28', '2001/03/29', '2001/03/31', '2001/04/01', '2001/04/12', '2001/04/14', '2001/04/17', '2001/04/24', '2001/04/26', '2001/04/30', '2001/05/02', '2001/05/03', '2001/05/09', '2001/05/18', '2001/05/19', '2001/05/26', '2001/06/01', '2001/06/05', '2001/06/10', '2001/06/11', '2001/06/12', '2001/06/22', '2001/06/23', '2001/06/24', '2001/06/26', '2001/06/27', '2001/07/04', '2001/07/05', '2001/07/06', '2001/07/08', '2001/07/09', '2001/07/13', '2001/07/16', '2001/07/20', '2001/07/21', '2001/07/22', '2001/07/26', '2001/07/27', '2001/07/31', '2001/08/03', '2001/08/04', '2001/08/05', '2001/08/07', '2001/08/08', '2001/08/15', '2001/08/21', '2001/08/22', '2001/08/23', '2001/08/25', '2001/08/26', '2001/08/31', '2001/09/02', '2001/09/04', '2001/09/07', '2001/09/08', '2001/09/11', '2001/09/13', '2001/09/14', '2001/09/18', '2001/09/19', '2001/09/20', '2001/09/26', '2001/09/29', '2001/09/30', '2001/10/02', '2001/10/05', '2001/10/07', '2001/10/16', '2001/10/17', '2001/10/21', '2001/10/23', '2001/10/24', '2001/10/27', '2001/10/29', '2001/10/30', '2001/11/03', '2001/11/09', '2001/11/15', '2001/11/17', '2001/11/25', '2001/11/28', '2001/12/01', '2001/12/05', '2001/12/12', '2001/12/13', '2001/12/20', '2001/12/22', '2001/12/24', '2001/12/30'], 'sta_B': ['2001/01/13', '2001/01/15', '2001/01/20', '2001/01/23', '2001/02/09', '2001/02/10', '2001/02/12', '2001/02/17', '2001/02/18', '2001/02/22', '2001/02/24', '2001/02/27', '2001/02/28', '2001/03/07', '2001/03/09', '2001/03/14', '2001/03/16', '2001/03/20', '2001/03/23', '2001/04/01', '2001/04/02', '2001/04/04', '2001/04/07', '2001/04/08', '2001/04/09', '2001/04/12', '2001/04/15', '2001/04/16', '2001/04/17', '2001/04/19', '2001/04/20', '2001/04/25', '2001/04/27', '2001/04/30', '2001/05/12', '2001/05/15', '2001/05/20', '2001/05/23', '2001/06/15', '2001/06/16', '2001/06/18', '2001/06/19', '2001/06/23', '2001/07/01', '2001/07/05', '2001/07/09', '2001/07/16', '2001/07/19', '2001/07/20', '2001/07/23', '2001/07/25', '2001/07/30', '2001/08/04', '2001/08/06', '2001/08/07', '2001/08/09', '2001/08/12', '2001/08/13', '2001/08/15', '2001/08/18', '2001/08/21', '2001/08/26', '2001/08/29', '2001/08/31', '2001/09/02', '2001/09/05', '2001/09/06', '2001/09/07', '2001/09/10', '2001/09/13', '2001/09/14', '2001/09/15', '2001/09/19', '2001/09/22', '2001/09/23', '2001/09/30', '2001/10/02', '2001/10/03', '2001/10/06', '2001/10/12', '2001/10/14', '2001/10/17', '2001/10/18', '2001/10/19', '2001/10/21', '2001/10/23', '2001/10/24', '2001/10/30', '2001/11/02', '2001/11/03', '2001/11/05', '2001/11/12', '2001/11/13', '2001/11/16', '2001/11/17', '2001/11/21', '2001/11/26', '2001/12/03', '2001/12/07', '2001/12/10', '2001/12/11', '2001/12/19', '2001/12/20', '2001/12/23', '2001/12/26', '2001/12/29', '2001/12/31'], 'sta_C': ['2001/01/09', '2001/01/12', '2001/01/13', '2001/01/17', '2001/01/22', '2001/01/23', '2001/01/24', '2001/01/26', '2001/02/02', '2001/02/04', '2001/02/08', '2001/02/10', '2001/02/11', '2001/02/16', '2001/02/18', '2001/02/22', '2001/03/06', '2001/03/07', '2001/03/08', '2001/03/10', '2001/03/19', '2001/03/20', '2001/03/21', '2001/03/22', '2001/03/24', '2001/03/26', '2001/03/27', '2001/03/28', '2001/04/04', '2001/04/07', '2001/04/11', '2001/04/15', '2001/04/17', '2001/04/18', '2001/04/23', '2001/04/24', '2001/04/26', '2001/04/27', '2001/04/28', '2001/04/30', '2001/05/11', '2001/05/13', '2001/05/17', '2001/05/19', '2001/05/24', '2001/05/28', '2001/05/29', '2001/05/31', '2001/06/05', '2001/06/06', '2001/06/10', '2001/06/14', '2001/06/15', '2001/06/18', '2001/06/20', '2001/06/22', '2001/06/23', '2001/06/25', '2001/06/28', '2001/07/03', '2001/07/05', '2001/07/08', '2001/07/09', '2001/07/10', '2001/07/11', '2001/07/12', '2001/07/13', '2001/07/18', '2001/07/27', '2001/07/30', '2001/07/31', '2001/08/02', '2001/08/06', '2001/08/14', '2001/08/20', '2001/08/24', '2001/08/26', '2001/08/29', '2001/08/30', '2001/09/08', '2001/09/12', '2001/09/15', '2001/09/21', '2001/09/24', '2001/09/27', '2001/10/02', '2001/10/03', '2001/10/04', '2001/10/05', '2001/10/09', '2001/10/13', '2001/10/14', '2001/10/15', '2001/10/21', '2001/10/23', '2001/10/26', '2001/11/02', '2001/11/07', '2001/11/09', '2001/11/13', '2001/11/16', '2001/11/25', '2001/11/29', '2001/12/06', '2001/12/07', '2001/12/12', '2001/12/22', '2001/12/23', '2001/12/30'], 'sta_D': ['2001/01/06', '2001/01/11', '2001/01/12', '2001/01/18', '2001/01/19', '2001/01/20', '2001/01/22', '2001/01/23', '2001/01/25', '2001/01/26', '2001/02/15', '2001/02/22', '2001/02/24', '2001/03/02', '2001/03/04', '2001/03/05', '2001/03/14', '2001/03/16', '2001/03/17', '2001/03/21', '2001/03/24', '2001/03/27', '2001/03/31', '2001/04/03', '2001/04/04', '2001/04/06', '2001/04/08', '2001/04/12', '2001/04/13', '2001/04/15', '2001/04/21', '2001/04/22', '2001/04/23', '2001/04/24', '2001/04/27', '2001/04/30', '2001/05/01', '2001/05/04', '2001/05/07', '2001/05/09', '2001/05/10', '2001/05/14', '2001/05/15', '2001/05/16', '2001/05/17', '2001/05/19', '2001/05/23', '2001/05/27', '2001/06/01', '2001/06/04', '2001/06/05', '2001/06/06', '2001/06/08', '2001/06/09', '2001/06/13', '2001/06/18', '2001/06/19', '2001/06/21', '2001/06/28', '2001/06/29', '2001/07/01', '2001/07/04', '2001/07/07', '2001/07/13', '2001/07/14', '2001/07/17', '2001/07/29', '2001/07/31', '2001/08/01', '2001/08/05', '2001/08/08', '2001/08/10', '2001/08/11', '2001/08/13', '2001/08/16', '2001/08/21', '2001/08/23', '2001/08/25', '2001/08/28', '2001/09/03', '2001/09/05', '2001/09/07', '2001/09/08', '2001/09/09', '2001/09/10', '2001/09/22', '2001/09/24', '2001/09/26', '2001/09/28', '2001/09/29', '2001/10/03', '2001/10/04', '2001/10/05', '2001/10/11', '2001/10/16', '2001/10/18', '2001/10/20', '2001/10/22', '2001/10/23', '2001/10/24', '2001/10/26', '2001/10/28', '2001/10/29', '2001/10/30', '2001/10/31', '2001/11/01', '2001/11/02', '2001/11/10', '2001/11/11', '2001/11/13', '2001/11/14', '2001/11/16', '2001/11/23', '2001/11/25', '2001/12/01', '2001/12/05', '2001/12/08', '2001/12/11', '2001/12/14', '2001/12/15', '2001/12/19', '2001/12/20'], 'sta_E': ['2001/01/04', '2001/01/07', '2001/01/08', '2001/01/18', '2001/01/21', '2001/01/27', '2001/02/04', '2001/02/10', '2001/02/12', '2001/02/13', '2001/02/16', '2001/02/24', '2001/02/25', '2001/02/27', '2001/03/14', '2001/03/15', '2001/03/20', '2001/03/23', '2001/03/27', '2001/03/29', '2001/04/01', '2001/04/02', '2001/04/08', '2001/04/11', '2001/04/17', '2001/04/18', '2001/04/21', '2001/04/24', '2001/04/26', '2001/05/01', '2001/05/04', '2001/05/09', '2001/05/13', '2001/05/15', '2001/05/18', '2001/05/19', '2001/06/06', '2001/06/08', '2001/06/12', '2001/06/14', '2001/06/19', '2001/07/01', '2001/07/06', '2001/07/11', '2001/07/13', '2001/07/14', '2001/07/15', '2001/07/16', '2001/07/20', '2001/07/23', '2001/07/27', '2001/07/29', '2001/08/01', '2001/08/02', '2001/08/03', '2001/08/06', '2001/08/09', '2001/08/10', '2001/08/11', '2001/08/14', '2001/08/18', '2001/08/20', '2001/08/24', '2001/08/29', '2001/08/30', '2001/09/06', '2001/09/11', '2001/09/13', '2001/09/15', '2001/09/16', '2001/09/24', '2001/09/29', '2001/10/04', '2001/10/11', '2001/10/12', '2001/10/13', '2001/10/18', '2001/10/21', '2001/10/22', '2001/10/24', '2001/10/26', '2001/10/27', '2001/10/28', '2001/10/29', '2001/11/02', '2001/11/03', '2001/11/04', '2001/11/05', '2001/11/07', '2001/11/08', '2001/11/12', '2001/11/13', '2001/11/19', '2001/11/20', '2001/11/23', '2001/11/24', '2001/11/28', '2001/12/01', '2001/12/03', '2001/12/09', '2001/12/16', '2001/12/18', '2001/12/21', '2001/12/26'], 'sta_F': ['2001/01/01', '2001/01/03', '2001/01/07', '2001/01/09', '2001/01/11', '2001/01/21', '2001/01/23', '2001/01/25', '2001/01/31', '2001/02/01', '2001/02/02', '2001/02/06', '2001/02/07', '2001/02/10', '2001/02/16', '2001/02/19', '2001/02/20', '2001/02/21', '2001/02/24', '2001/03/01', '2001/03/09', '2001/03/11', '2001/03/13', '2001/03/15', '2001/03/19', '2001/03/25', '2001/03/26', '2001/03/27', '2001/04/01', '2001/04/02', '2001/04/04', '2001/04/05', '2001/04/06', '2001/04/10', '2001/04/15', '2001/05/05', '2001/05/06', '2001/05/07', '2001/05/11', '2001/05/15', '2001/05/16', '2001/05/18', '2001/05/19', '2001/05/20', '2001/06/04', '2001/06/06', '2001/06/11', '2001/06/17', '2001/06/19', '2001/06/22', '2001/06/26', '2001/06/27', '2001/06/28', '2001/07/01', '2001/07/02', '2001/07/03', '2001/07/04', '2001/07/05', '2001/07/09', '2001/07/15', '2001/07/17', '2001/07/22', '2001/07/23', '2001/07/26', '2001/07/28', '2001/08/06', '2001/08/07', '2001/08/10', '2001/08/11', '2001/08/12', '2001/08/13', '2001/08/17', '2001/08/18', '2001/08/21', '2001/08/24', '2001/08/28', '2001/08/29', '2001/09/05', '2001/09/16', '2001/09/20', '2001/09/21', '2001/09/25', '2001/09/26', '2001/09/27', '2001/10/04', '2001/10/11', '2001/10/16', '2001/10/18', '2001/10/20', '2001/10/22', '2001/10/27', '2001/11/02', '2001/11/03', '2001/11/05', '2001/11/07', '2001/11/10', '2001/11/12', '2001/11/27', '2001/11/28', '2001/12/04', '2001/12/08', '2001/12/11', '2001/12/12', '2001/12/16', '2001/12/20', '2001/12/21', '2001/12/24']}\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "Tb48vl3soRrW", "colab_type": "code", "outputId": "a2b75b4c-2969-41eb-cc94-96e34874202b", "colab": { "base_uri": "https://localhost:8080/", "height": 54 } }, "source": [ "# Menampilkan kehilangan 20 data pertama pada stasiun A \n", "print(data_hilang['sta_A'][:20])" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "['2001/01/01', '2001/01/02', '2001/01/07', '2001/01/08', '2001/01/11', '2001/01/14', '2001/01/16', '2001/01/19', '2001/01/25', '2001/01/30', '2001/02/02', '2001/02/05', '2001/02/08', '2001/02/10', '2001/02/11', '2001/02/20', '2001/02/21', '2001/02/22', '2001/02/25', '2001/02/28']\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "0xZTr8KxmYqM", "colab_type": "code", "outputId": "07385db4-b775-41d1-d2de-15711cd00886", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "# Membaca data hilang pada bulan tertentu di stasiun B\n", "data_hilang_januari = read.missing_row(dataset['20010101':'20010201'][:-1])\n", "print(data_hilang_januari['sta_B'])" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "['2001/01/13', '2001/01/15', '2001/01/20', '2001/01/23']\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "BZ0ynD0OoiSI", "colab_type": "text" }, "source": [ "### Argumen `date_format`\n", "\n", "Dari hasil diatas diketahui format tanggal berupa `YYYY/MM/DD`. Karena kita tahu bahwa dataset ini pada tahun yang sama, maka informasi tahun bisa dihilangkan. Dan kita ingin mengganti format tanggal menjadi lebih sederhana dan jelas yaitu `MMM-DD` (contoh: `Jan-01`)\n", "\n", "Kita bisa mengubah format tanggal menggunakan [penulisan strftime](http://strftime.org/)." ] }, { "cell_type": "code", "metadata": { "id": "VlU0F7u5pY8B", "colab_type": "code", "outputId": "11495c56-b96b-4050-c533-4f35670c218f", "colab": { "base_uri": "https://localhost:8080/", "height": 71 } }, "source": [ "# Membaca data hilang dengan format tanggal tertentu\n", "data_hilang = read.missing_row(dataset, date_format='%b-%d')\n", "\n", "# Menampilkan data yang hilang pada stasiun C dan D\n", "print('Data yang hilang di stasiun C: ', data_hilang['sta_C'])\n", "print('Data yang hilang di stasiun D: ', data_hilang['sta_D'][:10]) # 10 data hilang pertama" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "Data yang hilang di stasiun C: ['Jan-09', 'Jan-12', 'Jan-13', 'Jan-17', 'Jan-22', 'Jan-23', 'Jan-24', 'Jan-26', 'Feb-02', 'Feb-04', 'Feb-08', 'Feb-10', 'Feb-11', 'Feb-16', 'Feb-18', 'Feb-22', 'Mar-06', 'Mar-07', 'Mar-08', 'Mar-10', 'Mar-19', 'Mar-20', 'Mar-21', 'Mar-22', 'Mar-24', 'Mar-26', 'Mar-27', 'Mar-28', 'Apr-04', 'Apr-07', 'Apr-11', 'Apr-15', 'Apr-17', 'Apr-18', 'Apr-23', 'Apr-24', 'Apr-26', 'Apr-27', 'Apr-28', 'Apr-30', 'May-11', 'May-13', 'May-17', 'May-19', 'May-24', 'May-28', 'May-29', 'May-31', 'Jun-05', 'Jun-06', 'Jun-10', 'Jun-14', 'Jun-15', 'Jun-18', 'Jun-20', 'Jun-22', 'Jun-23', 'Jun-25', 'Jun-28', 'Jul-03', 'Jul-05', 'Jul-08', 'Jul-09', 'Jul-10', 'Jul-11', 'Jul-12', 'Jul-13', 'Jul-18', 'Jul-27', 'Jul-30', 'Jul-31', 'Aug-02', 'Aug-06', 'Aug-14', 'Aug-20', 'Aug-24', 'Aug-26', 'Aug-29', 'Aug-30', 'Sep-08', 'Sep-12', 'Sep-15', 'Sep-21', 'Sep-24', 'Sep-27', 'Oct-02', 'Oct-03', 'Oct-04', 'Oct-05', 'Oct-09', 'Oct-13', 'Oct-14', 'Oct-15', 'Oct-21', 'Oct-23', 'Oct-26', 'Nov-02', 'Nov-07', 'Nov-09', 'Nov-13', 'Nov-16', 'Nov-25', 'Nov-29', 'Dec-06', 'Dec-07', 'Dec-12', 'Dec-22', 'Dec-23', 'Dec-30']\n", "Data yang hilang di stasiun D: ['Jan-06', 'Jan-11', 'Jan-12', 'Jan-18', 'Jan-19', 'Jan-20', 'Jan-22', 'Jan-23', 'Jan-25', 'Jan-26']\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "LV7f8I8nqe_l", "colab_type": "text" }, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": { "id": "g1erqYFbqvEx", "colab_type": "text" }, "source": [ "# Changelog\n", "\n", "```\n", "- 20190713 - 1.0.1 - Informasi notebook\n", "- 20190712 - 1.0.0 - Initial\n", "```" ] }, { "cell_type": "markdown", "metadata": { "id": "Lm-HngCMeMMH", "colab_type": "text" }, "source": [ "#### Copyright © 2019 [Taruma Sakti Megariansyah](https://taruma.github.io)\n", "\n", "Source code in this notebook is licensed under a [MIT License](https://opensource.org/licenses/MIT). Data in this notebook is licensed under a [Creative Common Attribution 4.0 International](https://choosealicense.com/licenses/cc-by-4.0/). " ] } ] }