Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active April 13, 2024 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taruma/a9dd4ea61db2526853b99600909e9c50 to your computer and use it in GitHub Desktop.
Save taruma/a9dd4ea61db2526853b99600909e9c50 to your computer and use it in GitHub Desktop.
taruma_hk43_pivot_table.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk43_pivot_table.ipynb",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/taruma/a9dd4ea61db2526853b99600909e9c50/taruma_hk43_pivot_table.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "umwHNSVwKfOM"
},
"source": [
"Berdasarkan isu [#43](https://github.com/taruma/hidrokit/issues/43): **ask: ubah pivot table ke dataframe**.\n",
"\n",
"Deskripsi permasalahan (baca isu untuk lebih merinci):\n",
"- Saya memiliki (pivot) table yang berada di dalam berkas excel.\n",
"- Saya ingin mengubah pivot table menjadi dataframe.\n",
"- (Lanjutan) Saya ingin mengambil data (pivot table) dari seluruh sheet di dalam berkas excel.\n",
"- (Lanjutan) Memeriksa apakah terdapat data yang _invalid_.\n",
"\n",
"Strategi penyelesaian:\n",
"- Memperoleh pivot table dari berkas excel.\n",
"- Transformasi pivot table ke dalam bentuk biasa (kolom tunggal/tahun).\n",
"- Menggabungkan hasil transformasi untuk masing-masing stasiun.\n",
"- Saat menggabungkan diperiksa juga kondisi data (cek _invalid_).\n"
]
},
{
"cell_type": "markdown",
"source": [
"# SETUP"
],
"metadata": {
"id": "k2iHpFAnwycI"
}
},
{
"cell_type": "code",
"source": [
"import logging\n",
"# Get the root logger\n",
"logger = logging.getLogger()\n",
"# If the logger has handlers, remove them\n",
"if logger.hasHandlers():\n",
" logger.handlers.clear()\n",
"\n",
"# Set the logging level and format\n",
"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n",
"\n",
"logging.info(\"This is an info message\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "QJez4GJGwtmp",
"outputId": "e84cda74-d414-48cd-e44f-a1ea5b6d136f"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"2024-04-13 23:36:37,362 - INFO - This is an info message\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import warnings\n",
"import functools\n",
"\n",
"\n",
"def deprecated(new_func_name):\n",
" \"\"\"\n",
" Decorator to mark a function as deprecated.\n",
"\n",
" Parameters:\n",
" - new_func_name (str): The name of the new function that should be used instead.\n",
"\n",
" Returns:\n",
" - wrapper (function): The decorated function.\n",
"\n",
" Example:\n",
" @deprecated(\"new_function\")\n",
" def old_function():\n",
" pass\n",
"\n",
" The above example will generate a warning when `old_function` is called,\n",
" suggesting to use `new_function` instead.\n",
" \"\"\"\n",
"\n",
" def decorator(func):\n",
" @functools.wraps(func)\n",
" def wrapper(*args, **kwargs):\n",
" warnings.warn(\n",
" f\"{func.__name__} is deprecated, use {new_func_name} instead\",\n",
" DeprecationWarning,\n",
" )\n",
" return func(*args, **kwargs)\n",
"\n",
" return wrapper\n",
"\n",
" return decorator\n"
],
"metadata": {
"id": "mYb7bHpvw0Gb"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "m2e8vLE-OiBi"
},
"source": [
"# DATASET"
]
},
{
"cell_type": "code",
"metadata": {
"id": "errK-LcFPNFg"
},
"source": [
"FILE_PATH = 'debit_bd_pamarayan_1998_2008.xls'\n",
"DRIVE_DATASET_PATH = '/content/'\n",
"SINGLE_DATASET = DRIVE_DATASET_PATH + FILE_PATH"
],
"execution_count": 3,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "aD4TtSjLUQ70"
},
"source": [
"# FUNGSI"
]
},
{
"cell_type": "code",
"metadata": {
"id": "GjwhIJVRSnI0",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "28b3e0bb-bbc0-41a6-dda5-84eebf159648"
},
"source": [
"from calendar import isleap\n",
"from collections import defaultdict\n",
"from pathlib import Path\n",
"from typing import Callable, Any, Dict, Union, List\n",
"import logging\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"DROP_INDICES = [59, 60, 61, 123, 185, 278, 340]\n",
"DROP_INDICES_LEAP = [60, 61, 123, 185, 278, 340]\n",
"\n",
"\n",
"def _extract_years_from_excel(file_path: str) -> List[int]:\n",
" \"\"\"\n",
" Get a list of years from an Excel file.\n",
"\n",
" Parameters:\n",
" file_path (str): The path to the Excel file.\n",
"\n",
" Returns:\n",
" List[int]: A sorted list of years found in the Excel file.\n",
" \"\"\"\n",
" excel = pd.ExcelFile(file_path)\n",
" years = []\n",
" for sheet in excel.sheet_names:\n",
" if sheet.isdigit():\n",
" years.append(int(sheet))\n",
" return sorted(years)\n",
"\n",
"\n",
"def _get_pivot_from_excel(excel_file: str, year: int, data_format: str) -> pd.DataFrame:\n",
" \"\"\"\n",
" Get a pivot table from an Excel file.\n",
"\n",
" Parameters:\n",
" excel_file (str): The path to the Excel file.\n",
" year (int): The year of the data to retrieve.\n",
" data_format (str): The format of the data to retrieve.\n",
"\n",
" Returns:\n",
" pandas.DataFrame: The pivot table containing the data.\n",
"\n",
" Raises:\n",
" ValueError: If the data format is unknown.\n",
" \"\"\"\n",
" # Map data formats to parameters\n",
" formats = {\n",
" \"uma.debit\": (\"AN:AY\", 16, 47),\n",
" \"uma.hujan\": (\"B:M\", 19, 50),\n",
" }\n",
"\n",
" if data_format not in formats:\n",
" raise ValueError(f\"Unknown data format: {data_format}\")\n",
"\n",
" usecols, start_row, end_row = formats[data_format]\n",
"\n",
" # Read the Excel data\n",
" df = pd.read_excel(excel_file, sheet_name=str(year), header=None, usecols=usecols)\n",
"\n",
" # Return the pivot\n",
" return df.iloc[start_row:end_row, :]\n",
"\n",
"\n",
"def _get_data_for_year(file_path: str, year: int, data_format: str) -> np.ndarray:\n",
" \"\"\"\n",
" Get data for a specific year from a file and return it as a single vector numpy array.\n",
"\n",
" Parameters:\n",
" file_path (str): The path to the file.\n",
" year (int): The year for which to retrieve the data.\n",
" data_format (str): The format of the data.\n",
"\n",
" Returns:\n",
" numpy.ndarray: The data for the specified year.\n",
"\n",
" Raises:\n",
" ValueError: If the year is not a positive integer.\n",
" IOError: If the file cannot be read.\n",
" \"\"\"\n",
" if not isinstance(year, int) or year < 0:\n",
" raise ValueError(\"Year must be a positive integer.\")\n",
"\n",
" try:\n",
" pivot_table = _get_pivot_from_excel(\n",
" file_path, str(year), data_format=data_format\n",
" )\n",
" except Exception as e:\n",
" raise IOError(\"Could not read file: \" + str(e)) from e\n",
"\n",
" reshaped_data = pivot_table.melt().drop(\"variable\", axis=1)\n",
"\n",
" if isleap(year):\n",
" return reshaped_data[\"value\"].drop(DROP_INDICES_LEAP).values\n",
" return reshaped_data[\"value\"].drop(DROP_INDICES).values\n",
"\n",
"\n",
"def _get_data_all_year(\n",
" file_path: Union[str, Path], data_format: str, return_as_list: bool = False\n",
") -> Union[List[np.ndarray], np.ndarray]:\n",
" \"\"\"\n",
" Get data for all years from a given file.\n",
"\n",
" Args:\n",
" file_path (Union[str, Path]): The path to the file.\n",
" data_format (str): The format of the data.\n",
" return_as_list (bool, optional): Whether to return the data as a list of arrays.\n",
" Defaults to False.\n",
"\n",
" Returns:\n",
" Union[List[np.ndarray], np.ndarray]: The data for all years.\n",
"\n",
" Raises:\n",
" FileNotFoundError: If the file does not exist.\n",
" \"\"\"\n",
" file_path = Path(file_path)\n",
"\n",
" if not file_path.exists():\n",
" raise FileNotFoundError(f\"No such file or directory: '{file_path}'\")\n",
"\n",
" list_years = _extract_years_from_excel(file_path)\n",
"\n",
" data_each_year = []\n",
"\n",
" for year in list_years:\n",
" data = _get_data_for_year(file_path, year=year, data_format=data_format)\n",
" data_each_year.append(data)\n",
"\n",
" if return_as_list:\n",
" return data_each_year\n",
"\n",
" return np.hstack(data_each_year)\n",
"\n",
"\n",
"def _get_invalid_elements_indices(\n",
" num_array: Any, validation_func: Callable[[Any], Any]\n",
") -> Dict[str, List[int]]:\n",
" \"\"\"\n",
" Returns a dictionary containing the indices of invalid elements in the given `num_array`.\n",
"\n",
" Parameters:\n",
" - num_array (array-like): The array containing the elements to be validated.\n",
" - validation_func (function): The validation function to be applied to each element.\n",
"\n",
" Returns:\n",
" - invalid_element_indices (defaultdict):\n",
" A defaultdict object containing the indices of invalid elements.\n",
" The keys of the dictionary represent the type of invalidity,\n",
" such as \"NaN\" for elements that are NaN, and\n",
" the values are lists of indices corresponding to each type of invalidity.\n",
" \"\"\"\n",
" invalid_element_indices: Dict[str, List[int]] = defaultdict(list)\n",
" for index, element in enumerate(num_array):\n",
" try:\n",
" result = validation_func(element)\n",
" if np.isnan(result):\n",
" invalid_element_indices[\"NaN\"].append(index)\n",
" except ValueError:\n",
" invalid_element_indices[str(element)].append(index)\n",
"\n",
" return invalid_element_indices\n",
"\n",
"\n",
"def have_invalid(array: List[Any], validation_func: Callable[[Any], Any]) -> bool:\n",
" \"\"\"\n",
" Check if the given array has any invalid elements based on the provided validation function.\n",
"\n",
" Args:\n",
" array (list): The array to check for invalid elements.\n",
" validation_func (function): The validation function used\n",
" to determine if an element is invalid.\n",
"\n",
" Returns:\n",
" bool: True if the array has any invalid elements, False otherwise.\n",
" \"\"\"\n",
" return bool(_get_invalid_elements_indices(array, validation_func=validation_func))\n",
"\n",
"\n",
"def _check_invalid(array, validation_func=float):\n",
" \"\"\"\n",
" Check if there are any invalid elements in the array.\n",
"\n",
" Parameters:\n",
" array (iterable): The array to check.\n",
" validation_func (callable): The validation function to use.\n",
"\n",
" Returns:\n",
" dict or None: A dictionary with the indices of invalid elements,\n",
" or None if there are no invalid elements.\n",
" \"\"\"\n",
" invalid_elements_indices = _get_invalid_elements_indices(\n",
" array, validation_func=validation_func\n",
" )\n",
" return invalid_elements_indices if invalid_elements_indices is not None else None\n",
"\n",
"\n",
"def read_folder(\n",
" dataset_path: str,\n",
" filename_pattern: str,\n",
" data_format: str,\n",
" station_name_prefix: str = \"\",\n",
" check_for_invalid_data: bool = False,\n",
") -> Union[Dict[str, np.ndarray], Dict[str, np.ndarray], Dict[str, List[int]]]:\n",
" \"\"\"\n",
" Read files from a folder and extract data for each station.\n",
"\n",
" Args:\n",
" dataset_path (str): The path to the dataset folder.\n",
" filename_pattern (str): The pattern to match the filenames.\n",
" data_format (str): The format of the data in the files.\n",
" station_name_prefix (str, optional): The prefix to add to the station names.\n",
" Defaults to \"\".\n",
" check_for_invalid_data (bool, optional): Whether to check for invalid data.\n",
" Defaults to False.\n",
"\n",
" Returns:\n",
" dict: A dictionary containing the extracted data for each station.\n",
" If `check_for_invalid_data` is True,\n",
" it also returns a dictionary of invalid data for each station.\n",
" \"\"\"\n",
" dataset_path = Path(dataset_path)\n",
" all_files = list(dataset_path.rglob(filename_pattern))\n",
" total_files = len(all_files)\n",
"\n",
" if total_files == 0:\n",
" logging.warning(\"No files found that match the pattern %s\", filename_pattern)\n",
" return {}\n",
"\n",
" logging.info(\"Found %d file(s)\", total_files)\n",
"\n",
" all_station_data = {}\n",
" invalid_data = {}\n",
"\n",
" for counter, file in enumerate(dataset_path.glob(filename_pattern)):\n",
" logging.info(\":: %4d:\\t%s\", counter, file.name)\n",
" station_name = station_name_prefix + \"_\".join(file.stem.split(\"_\")[1:-2])\n",
" each_station_data = _get_data_all_year(file, data_format=data_format)\n",
" all_station_data[station_name] = each_station_data\n",
" if check_for_invalid_data:\n",
" invalid_data[station_name] = _check_invalid(each_station_data)\n",
"\n",
" if check_for_invalid_data:\n",
" return all_station_data, invalid_data\n",
" return all_station_data\n",
"\n",
"\n",
"@deprecated(\"_extract_years_from_excel\")\n",
"def _get_years(io: str) -> List[int]:\n",
" return _extract_years_from_excel(io)\n",
"\n",
"\n",
"@deprecated(\"_get_pivot_from_excel\")\n",
"def _get_pivot(io, year, fmt):\n",
" return _get_pivot_from_excel(io, year, fmt)\n",
"\n",
"\n",
"@deprecated(\"_get_data_for_year\")\n",
"def _get_data_oneyear(io, year, fmt):\n",
" return _get_data_for_year(io, year, fmt)\n",
"\n",
"\n",
"@deprecated(\"_get_data_all_year\")\n",
"def _get_data_allyear(*args, **kwargs):\n",
" return _get_data_all_year(*args, **kwargs)\n",
"\n",
"\n",
"@deprecated(\"_get_invalid_elements_indices\")\n",
"def _get_invalid(array, check):\n",
" return _get_invalid_elements_indices(array, validation_func=check)\n",
"\n",
"\n",
"@deprecated(\"have_invalid\")\n",
"def _have_invalid(array, check):\n",
" return have_invalid(array, validation_func=check)"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"2024-04-13 23:36:37,620 - INFO - NumExpr defaulting to 2 threads.\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "X8w9NdVrQ3T7"
},
"source": [
"# DATA"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KbekbUdQQ5SA"
},
"source": [
"## Fungsi _private_ `_get_years()`\n",
"\n",
"Tujuan: Memperoleh `list` tahun di dalam berkas excel."
]
},
{
"cell_type": "code",
"metadata": {
"id": "qR6pVRsOQqeU",
"outputId": "3ff2697c-bb48-41de-e52e-d11cd8906da6",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_years(SINGLE_DATASET)"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_years is deprecated, use _extract_years_from_excel instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008]"
]
},
"metadata": {},
"execution_count": 5
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7BaOnrmAPCdN"
},
"source": [
"## Fungsi _private_ `_get_pivot()`\n",
"\n",
"Tujuan: memperoleh pivot table dari berkas excel"
]
},
{
"cell_type": "code",
"metadata": {
"id": "iBAOsnzmPLvz",
"outputId": "4ef38e34-61d7-41cf-852a-53c250aa760b",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"_get_pivot(SINGLE_DATASET, year=1998, fmt='uma.debit')"
],
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_pivot is deprecated, use _get_pivot_from_excel instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 39 40 41 42 43 44 45 46 47 48 \\\n",
"16 0 0 90.12 74.6 160.28 22.1 19.96 24.82 490 56.36 \n",
"17 0 0 97.9 126.44 167.16 318.52 21.46 25.22 11.36 52.38 \n",
"18 0 0 88.9 128.08 132.3 105.66 21.74 139.18 54.06 19.16 \n",
"19 0 0 90.3 126.72 202.8 99.38 22.5 63.68 78.68 22.46 \n",
"20 0 0 210.06 74.36 80.4 173.96 21.9 173.82 14.54 135.92 \n",
"21 0 0 82.9 78.08 204.54 84.58 24.94 170.98 78.28 89.18 \n",
"22 0 0 274.42 120.18 88.12 84.06 24.5 19.46 165.48 83.58 \n",
"23 0 0 216.36 75.18 77.48 24.82 23.62 19.86 168.18 80.6 \n",
"24 0 0 86.84 30.38 207.28 23.26 24.02 20.82 22 20.62 \n",
"25 0 0 88.68 92.98 206.4 18.66 25.82 21.42 84.04 19.52 \n",
"26 0 0 80.8 30.38 284.3 51.1 26.26 23.78 21.74 16.56 \n",
"27 0 0 84.3 158.7 351.76 20.7 20.4 27.76 58.86 82.62 \n",
"28 0 0 82.3 348.8 83.44 19.96 17.62 58.14 21.52 84.02 \n",
"29 0 0 120.96 77.46 233.52 20.36 15.34 116.7 19.84 21.74 \n",
"30 0 0 123.28 77.32 81.78 83.12 18.34 115.82 23.1 80.98 \n",
"31 0 0 131.06 128.6 81.98 22.24 19.3 24.42 14.84 20 \n",
"32 0 0 74.86 161.92 82.18 19.74 80.94 22.82 20.38 18.75 \n",
"33 0 0 159.66 388.18 84.3 19.02 167.76 21.44 20.28 275.19 \n",
"34 0 0 69.68 123.62 86.56 17.76 133.76 24.38 20.14 252.96 \n",
"35 0 0 68.36 129.34 22.46 49.6 162.44 24.62 15.48 63.58 \n",
"36 0 0 73.56 157.76 20.74 54.42 94.98 111.78 22.8 77.27 \n",
"37 0 0 74.64 129.98 83.54 87.22 172.52 20.22 19.46 81.04 \n",
"38 0 0 84.96 14.76 15.08 22.54 134.14 22.78 19.64 49.5 \n",
"39 0 0 376.54 84.9 13.92 19.96 82.94 24.68 57.28 18.42 \n",
"40 0 0 126.76 74.76 64.24 85.24 23.16 83.28 23.18 15.52 \n",
"41 0 0 128.22 76.88 19.96 212.46 22.98 22.28 21.62 120.14 \n",
"42 0 0 125.46 124.6 21.84 84.7 84.62 22.22 19.46 213.97 \n",
"43 0 0 444.62 133.6 96.9 83.58 24.04 162.64 17.1 367.19 \n",
"44 0 NaN 154.68 154.96 113.88 19.94 21.82 13.08 14.3 104.2 \n",
"45 0 NaN 11.68 348.8 85.06 17.58 22.58 170.36 14.44 78.65 \n",
"46 0 NaN 77.12 NaN 93.24 NaN 63.56 84.68 NaN 80.67 \n",
"\n",
" 49 50 \n",
"16 158.84 54.58 \n",
"17 79.96 56.45 \n",
"18 58.98 26.7 \n",
"19 283.04 84.02 \n",
"20 166.48 81.28 \n",
"21 20.9.46 82.28 \n",
"22 238.98 50.18 \n",
"23 81.46 166.02 \n",
"24 79.52 166.42 \n",
"25 75.92 84.38 \n",
"26 44.92 51.4 \n",
"27 255.4 24.62 \n",
"28 161.98 24.62 \n",
"29 133.68 70 \n",
"30 52.42 68.3 \n",
"31 85.36 68.9 \n",
"32 55.5 25.22 \n",
"33 266.18 27.32 \n",
"34 162.38 25.9 \n",
"35 166.58 26.06 \n",
"36 133.56 70.32 \n",
"37 133 121.32 \n",
"38 81.76 69.6 \n",
"39 133.98 139.83 \n",
"40 48.16 88.9 \n",
"41 84.25 417 \n",
"42 20.62 164.75 \n",
"43 20.78 253.8 \n",
"44 21.38 77.54 \n",
"45 24.8 157.76 \n",
"46 NaN 309.58 "
],
"text/html": [
"\n",
" <div id=\"df-318e4400-4c56-46d8-beb3-dd414d8e8f96\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>39</th>\n",
" <th>40</th>\n",
" <th>41</th>\n",
" <th>42</th>\n",
" <th>43</th>\n",
" <th>44</th>\n",
" <th>45</th>\n",
" <th>46</th>\n",
" <th>47</th>\n",
" <th>48</th>\n",
" <th>49</th>\n",
" <th>50</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>90.12</td>\n",
" <td>74.6</td>\n",
" <td>160.28</td>\n",
" <td>22.1</td>\n",
" <td>19.96</td>\n",
" <td>24.82</td>\n",
" <td>490</td>\n",
" <td>56.36</td>\n",
" <td>158.84</td>\n",
" <td>54.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>97.9</td>\n",
" <td>126.44</td>\n",
" <td>167.16</td>\n",
" <td>318.52</td>\n",
" <td>21.46</td>\n",
" <td>25.22</td>\n",
" <td>11.36</td>\n",
" <td>52.38</td>\n",
" <td>79.96</td>\n",
" <td>56.45</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>88.9</td>\n",
" <td>128.08</td>\n",
" <td>132.3</td>\n",
" <td>105.66</td>\n",
" <td>21.74</td>\n",
" <td>139.18</td>\n",
" <td>54.06</td>\n",
" <td>19.16</td>\n",
" <td>58.98</td>\n",
" <td>26.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>90.3</td>\n",
" <td>126.72</td>\n",
" <td>202.8</td>\n",
" <td>99.38</td>\n",
" <td>22.5</td>\n",
" <td>63.68</td>\n",
" <td>78.68</td>\n",
" <td>22.46</td>\n",
" <td>283.04</td>\n",
" <td>84.02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>210.06</td>\n",
" <td>74.36</td>\n",
" <td>80.4</td>\n",
" <td>173.96</td>\n",
" <td>21.9</td>\n",
" <td>173.82</td>\n",
" <td>14.54</td>\n",
" <td>135.92</td>\n",
" <td>166.48</td>\n",
" <td>81.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>82.9</td>\n",
" <td>78.08</td>\n",
" <td>204.54</td>\n",
" <td>84.58</td>\n",
" <td>24.94</td>\n",
" <td>170.98</td>\n",
" <td>78.28</td>\n",
" <td>89.18</td>\n",
" <td>20.9.46</td>\n",
" <td>82.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>274.42</td>\n",
" <td>120.18</td>\n",
" <td>88.12</td>\n",
" <td>84.06</td>\n",
" <td>24.5</td>\n",
" <td>19.46</td>\n",
" <td>165.48</td>\n",
" <td>83.58</td>\n",
" <td>238.98</td>\n",
" <td>50.18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>216.36</td>\n",
" <td>75.18</td>\n",
" <td>77.48</td>\n",
" <td>24.82</td>\n",
" <td>23.62</td>\n",
" <td>19.86</td>\n",
" <td>168.18</td>\n",
" <td>80.6</td>\n",
" <td>81.46</td>\n",
" <td>166.02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>86.84</td>\n",
" <td>30.38</td>\n",
" <td>207.28</td>\n",
" <td>23.26</td>\n",
" <td>24.02</td>\n",
" <td>20.82</td>\n",
" <td>22</td>\n",
" <td>20.62</td>\n",
" <td>79.52</td>\n",
" <td>166.42</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>88.68</td>\n",
" <td>92.98</td>\n",
" <td>206.4</td>\n",
" <td>18.66</td>\n",
" <td>25.82</td>\n",
" <td>21.42</td>\n",
" <td>84.04</td>\n",
" <td>19.52</td>\n",
" <td>75.92</td>\n",
" <td>84.38</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>80.8</td>\n",
" <td>30.38</td>\n",
" <td>284.3</td>\n",
" <td>51.1</td>\n",
" <td>26.26</td>\n",
" <td>23.78</td>\n",
" <td>21.74</td>\n",
" <td>16.56</td>\n",
" <td>44.92</td>\n",
" <td>51.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>84.3</td>\n",
" <td>158.7</td>\n",
" <td>351.76</td>\n",
" <td>20.7</td>\n",
" <td>20.4</td>\n",
" <td>27.76</td>\n",
" <td>58.86</td>\n",
" <td>82.62</td>\n",
" <td>255.4</td>\n",
" <td>24.62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>82.3</td>\n",
" <td>348.8</td>\n",
" <td>83.44</td>\n",
" <td>19.96</td>\n",
" <td>17.62</td>\n",
" <td>58.14</td>\n",
" <td>21.52</td>\n",
" <td>84.02</td>\n",
" <td>161.98</td>\n",
" <td>24.62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>120.96</td>\n",
" <td>77.46</td>\n",
" <td>233.52</td>\n",
" <td>20.36</td>\n",
" <td>15.34</td>\n",
" <td>116.7</td>\n",
" <td>19.84</td>\n",
" <td>21.74</td>\n",
" <td>133.68</td>\n",
" <td>70</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>123.28</td>\n",
" <td>77.32</td>\n",
" <td>81.78</td>\n",
" <td>83.12</td>\n",
" <td>18.34</td>\n",
" <td>115.82</td>\n",
" <td>23.1</td>\n",
" <td>80.98</td>\n",
" <td>52.42</td>\n",
" <td>68.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>131.06</td>\n",
" <td>128.6</td>\n",
" <td>81.98</td>\n",
" <td>22.24</td>\n",
" <td>19.3</td>\n",
" <td>24.42</td>\n",
" <td>14.84</td>\n",
" <td>20</td>\n",
" <td>85.36</td>\n",
" <td>68.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>74.86</td>\n",
" <td>161.92</td>\n",
" <td>82.18</td>\n",
" <td>19.74</td>\n",
" <td>80.94</td>\n",
" <td>22.82</td>\n",
" <td>20.38</td>\n",
" <td>18.75</td>\n",
" <td>55.5</td>\n",
" <td>25.22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>159.66</td>\n",
" <td>388.18</td>\n",
" <td>84.3</td>\n",
" <td>19.02</td>\n",
" <td>167.76</td>\n",
" <td>21.44</td>\n",
" <td>20.28</td>\n",
" <td>275.19</td>\n",
" <td>266.18</td>\n",
" <td>27.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>69.68</td>\n",
" <td>123.62</td>\n",
" <td>86.56</td>\n",
" <td>17.76</td>\n",
" <td>133.76</td>\n",
" <td>24.38</td>\n",
" <td>20.14</td>\n",
" <td>252.96</td>\n",
" <td>162.38</td>\n",
" <td>25.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>68.36</td>\n",
" <td>129.34</td>\n",
" <td>22.46</td>\n",
" <td>49.6</td>\n",
" <td>162.44</td>\n",
" <td>24.62</td>\n",
" <td>15.48</td>\n",
" <td>63.58</td>\n",
" <td>166.58</td>\n",
" <td>26.06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>73.56</td>\n",
" <td>157.76</td>\n",
" <td>20.74</td>\n",
" <td>54.42</td>\n",
" <td>94.98</td>\n",
" <td>111.78</td>\n",
" <td>22.8</td>\n",
" <td>77.27</td>\n",
" <td>133.56</td>\n",
" <td>70.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>74.64</td>\n",
" <td>129.98</td>\n",
" <td>83.54</td>\n",
" <td>87.22</td>\n",
" <td>172.52</td>\n",
" <td>20.22</td>\n",
" <td>19.46</td>\n",
" <td>81.04</td>\n",
" <td>133</td>\n",
" <td>121.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>84.96</td>\n",
" <td>14.76</td>\n",
" <td>15.08</td>\n",
" <td>22.54</td>\n",
" <td>134.14</td>\n",
" <td>22.78</td>\n",
" <td>19.64</td>\n",
" <td>49.5</td>\n",
" <td>81.76</td>\n",
" <td>69.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>376.54</td>\n",
" <td>84.9</td>\n",
" <td>13.92</td>\n",
" <td>19.96</td>\n",
" <td>82.94</td>\n",
" <td>24.68</td>\n",
" <td>57.28</td>\n",
" <td>18.42</td>\n",
" <td>133.98</td>\n",
" <td>139.83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>126.76</td>\n",
" <td>74.76</td>\n",
" <td>64.24</td>\n",
" <td>85.24</td>\n",
" <td>23.16</td>\n",
" <td>83.28</td>\n",
" <td>23.18</td>\n",
" <td>15.52</td>\n",
" <td>48.16</td>\n",
" <td>88.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>128.22</td>\n",
" <td>76.88</td>\n",
" <td>19.96</td>\n",
" <td>212.46</td>\n",
" <td>22.98</td>\n",
" <td>22.28</td>\n",
" <td>21.62</td>\n",
" <td>120.14</td>\n",
" <td>84.25</td>\n",
" <td>417</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>125.46</td>\n",
" <td>124.6</td>\n",
" <td>21.84</td>\n",
" <td>84.7</td>\n",
" <td>84.62</td>\n",
" <td>22.22</td>\n",
" <td>19.46</td>\n",
" <td>213.97</td>\n",
" <td>20.62</td>\n",
" <td>164.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>444.62</td>\n",
" <td>133.6</td>\n",
" <td>96.9</td>\n",
" <td>83.58</td>\n",
" <td>24.04</td>\n",
" <td>162.64</td>\n",
" <td>17.1</td>\n",
" <td>367.19</td>\n",
" <td>20.78</td>\n",
" <td>253.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>154.68</td>\n",
" <td>154.96</td>\n",
" <td>113.88</td>\n",
" <td>19.94</td>\n",
" <td>21.82</td>\n",
" <td>13.08</td>\n",
" <td>14.3</td>\n",
" <td>104.2</td>\n",
" <td>21.38</td>\n",
" <td>77.54</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>11.68</td>\n",
" <td>348.8</td>\n",
" <td>85.06</td>\n",
" <td>17.58</td>\n",
" <td>22.58</td>\n",
" <td>170.36</td>\n",
" <td>14.44</td>\n",
" <td>78.65</td>\n",
" <td>24.8</td>\n",
" <td>157.76</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>77.12</td>\n",
" <td>NaN</td>\n",
" <td>93.24</td>\n",
" <td>NaN</td>\n",
" <td>63.56</td>\n",
" <td>84.68</td>\n",
" <td>NaN</td>\n",
" <td>80.67</td>\n",
" <td>NaN</td>\n",
" <td>309.58</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-318e4400-4c56-46d8-beb3-dd414d8e8f96')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-318e4400-4c56-46d8-beb3-dd414d8e8f96 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-318e4400-4c56-46d8-beb3-dd414d8e8f96');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-8cd36819-e75a-4070-a4d0-a05396cd3a7b\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-8cd36819-e75a-4070-a4d0-a05396cd3a7b')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-8cd36819-e75a-4070-a4d0-a05396cd3a7b button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"repr_error": "0"
}
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "RQuOApnXSYUV"
},
"source": [
"## Fungsi _private_ `_get_data_oneyear()`\n",
"\n",
"Tujuan: Memperoleh data dari _sheet_ tunggal dan disajikan dalam bentuk `array` 1D."
]
},
{
"cell_type": "code",
"metadata": {
"id": "NWaKaN-cSXgB",
"outputId": "eaa60218-d3b4-484e-b578-0d8578410496",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_data_oneyear(SINGLE_DATASET, year=1998, fmt='uma.debit')"
],
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_oneyear is deprecated, use _get_data_for_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90.12, 97.9, 88.9,\n",
" 90.3, 210.06, 82.9, 274.42, 216.36, 86.84, 88.68, 80.8, 84.3, 82.3,\n",
" 120.96, 123.28, 131.06, 74.86, 159.66, 69.68, 68.36, 73.56, 74.64,\n",
" 84.96, 376.54, 126.76, 128.22, 125.46, 444.62, 154.68, 11.68,\n",
" 77.12, 74.6, 126.44, 128.08, 126.72, 74.36, 78.08, 120.18, 75.18,\n",
" 30.38, 92.98, 30.38, 158.7, 348.8, 77.46, 77.32, 128.6, 161.92,\n",
" 388.18, 123.62, 129.34, 157.76, 129.98, 14.76, 84.9, 74.76, 76.88,\n",
" 124.6, 133.6, 154.96, 348.8, 160.28, 167.16, 132.3, 202.8, 80.4,\n",
" 204.54, 88.12, 77.48, 207.28, 206.4, 284.3, 351.76, 83.44, 233.52,\n",
" 81.78, 81.98, 82.18, 84.3, 86.56, 22.46, 20.74, 83.54, 15.08,\n",
" 13.92, 64.24, 19.96, 21.84, 96.9, 113.88, 85.06, 93.24, 22.1,\n",
" 318.52, 105.66, 99.38, 173.96, 84.58, 84.06, 24.82, 23.26, 18.66,\n",
" 51.1, 20.7, 19.96, 20.36, 83.12, 22.24, 19.74, 19.02, 17.76, 49.6,\n",
" 54.42, 87.22, 22.54, 19.96, 85.24, 212.46, 84.7, 83.58, 19.94,\n",
" 17.58, 19.96, 21.46, 21.74, 22.5, 21.9, 24.94, 24.5, 23.62, 24.02,\n",
" 25.82, 26.26, 20.4, 17.62, 15.34, 18.34, 19.3, 80.94, 167.76,\n",
" 133.76, 162.44, 94.98, 172.52, 134.14, 82.94, 23.16, 22.98, 84.62,\n",
" 24.04, 21.82, 22.58, 63.56, 24.82, 25.22, 139.18, 63.68, 173.82,\n",
" 170.98, 19.46, 19.86, 20.82, 21.42, 23.78, 27.76, 58.14, 116.7,\n",
" 115.82, 24.42, 22.82, 21.44, 24.38, 24.62, 111.78, 20.22, 22.78,\n",
" 24.68, 83.28, 22.28, 22.22, 162.64, 13.08, 170.36, 84.68, 490,\n",
" 11.36, 54.06, 78.68, 14.54, 78.28, 165.48, 168.18, 22, 84.04,\n",
" 21.74, 58.86, 21.52, 19.84, 23.1, 14.84, 20.38, 20.28, 20.14,\n",
" 15.48, 22.8, 19.46, 19.64, 57.28, 23.18, 21.62, 19.46, 17.1, 14.3,\n",
" 14.44, 56.36, 52.38, 19.16, 22.46, 135.92, 89.18, 83.58, 80.6,\n",
" 20.62, 19.52, 16.56, 82.62, 84.02, 21.74, 80.98, 20, 18.75, 275.19,\n",
" 252.96, 63.58, 77.27, 81.04, 49.5, 18.42, 15.52, 120.14, 213.97,\n",
" 367.19, 104.2, 78.65, 80.67, 158.84, 79.96, 58.98, 283.04, 166.48,\n",
" '20.9.46', 238.98, 81.46, 79.52, 75.92, 44.92, 255.4, 161.98,\n",
" 133.68, 52.42, 85.36, 55.5, 266.18, 162.38, 166.58, 133.56, 133,\n",
" 81.76, 133.98, 48.16, 84.25, 20.62, 20.78, 21.38, 24.8, 54.58,\n",
" 56.45, 26.7, 84.02, 81.28, 82.28, 50.18, 166.02, 166.42, 84.38,\n",
" 51.4, 24.62, 24.62, 70, 68.3, 68.9, 25.22, 27.32, 25.9, 26.06,\n",
" 70.32, 121.32, 69.6, 139.83, 88.9, 417, 164.75, 253.8, 77.54,\n",
" 157.76, 309.58], dtype=object)"
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "dGLzRL0dTQA5",
"outputId": "f400a74d-aa57-46f4-8931-03de3b41632b",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_data_oneyear(SINGLE_DATASET, year=1998, fmt='uma.debit').shape"
],
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_oneyear is deprecated, use _get_data_for_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(365,)"
]
},
"metadata": {},
"execution_count": 8
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4NEiOehaTBd8"
},
"source": [
"## Fungsi _private_ `_get_data_allyear()`\n",
"\n",
"Tujuan: Memeroleh data dari seluruh _sheet_ dan disajikan dalam bentuk `array` 1D."
]
},
{
"cell_type": "code",
"metadata": {
"id": "te2aZiWfSply",
"outputId": "b228dd27-33e2-414b-fb06-09c937d37beb",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_data_allyear(SINGLE_DATASET, 'uma.debit')"
],
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_allyear is deprecated, use _get_data_all_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([0, 0, 0, ..., 20.14, 208.54, 208.14], dtype=object)"
]
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "S0RFleEUTNIj",
"outputId": "a70ad9ba-f454-4782-fbc3-77b3151170ec",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_data_allyear(SINGLE_DATASET, 'uma.debit').shape"
],
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_allyear is deprecated, use _get_data_all_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(4018,)"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "G-7rGaOQTXYV"
},
"source": [
"### `aslist=True`\n",
"\n",
"Tujuan: disajikan dalam bentuk `list` `array` untuk setiap tahunnya."
]
},
{
"cell_type": "code",
"metadata": {
"id": "PbAeTg2tTTIM",
"outputId": "3055ce14-e866-416a-dbbe-4f4ee7178605",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_data_allyear(SINGLE_DATASET, data_format='uma.debit', return_as_list=True)[:2]"
],
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_allyear is deprecated, use _get_data_all_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90.12, 97.9, 88.9,\n",
" 90.3, 210.06, 82.9, 274.42, 216.36, 86.84, 88.68, 80.8, 84.3, 82.3,\n",
" 120.96, 123.28, 131.06, 74.86, 159.66, 69.68, 68.36, 73.56, 74.64,\n",
" 84.96, 376.54, 126.76, 128.22, 125.46, 444.62, 154.68, 11.68,\n",
" 77.12, 74.6, 126.44, 128.08, 126.72, 74.36, 78.08, 120.18, 75.18,\n",
" 30.38, 92.98, 30.38, 158.7, 348.8, 77.46, 77.32, 128.6, 161.92,\n",
" 388.18, 123.62, 129.34, 157.76, 129.98, 14.76, 84.9, 74.76, 76.88,\n",
" 124.6, 133.6, 154.96, 348.8, 160.28, 167.16, 132.3, 202.8, 80.4,\n",
" 204.54, 88.12, 77.48, 207.28, 206.4, 284.3, 351.76, 83.44, 233.52,\n",
" 81.78, 81.98, 82.18, 84.3, 86.56, 22.46, 20.74, 83.54, 15.08,\n",
" 13.92, 64.24, 19.96, 21.84, 96.9, 113.88, 85.06, 93.24, 22.1,\n",
" 318.52, 105.66, 99.38, 173.96, 84.58, 84.06, 24.82, 23.26, 18.66,\n",
" 51.1, 20.7, 19.96, 20.36, 83.12, 22.24, 19.74, 19.02, 17.76, 49.6,\n",
" 54.42, 87.22, 22.54, 19.96, 85.24, 212.46, 84.7, 83.58, 19.94,\n",
" 17.58, 19.96, 21.46, 21.74, 22.5, 21.9, 24.94, 24.5, 23.62, 24.02,\n",
" 25.82, 26.26, 20.4, 17.62, 15.34, 18.34, 19.3, 80.94, 167.76,\n",
" 133.76, 162.44, 94.98, 172.52, 134.14, 82.94, 23.16, 22.98, 84.62,\n",
" 24.04, 21.82, 22.58, 63.56, 24.82, 25.22, 139.18, 63.68, 173.82,\n",
" 170.98, 19.46, 19.86, 20.82, 21.42, 23.78, 27.76, 58.14, 116.7,\n",
" 115.82, 24.42, 22.82, 21.44, 24.38, 24.62, 111.78, 20.22, 22.78,\n",
" 24.68, 83.28, 22.28, 22.22, 162.64, 13.08, 170.36, 84.68, 490,\n",
" 11.36, 54.06, 78.68, 14.54, 78.28, 165.48, 168.18, 22, 84.04,\n",
" 21.74, 58.86, 21.52, 19.84, 23.1, 14.84, 20.38, 20.28, 20.14,\n",
" 15.48, 22.8, 19.46, 19.64, 57.28, 23.18, 21.62, 19.46, 17.1, 14.3,\n",
" 14.44, 56.36, 52.38, 19.16, 22.46, 135.92, 89.18, 83.58, 80.6,\n",
" 20.62, 19.52, 16.56, 82.62, 84.02, 21.74, 80.98, 20, 18.75, 275.19,\n",
" 252.96, 63.58, 77.27, 81.04, 49.5, 18.42, 15.52, 120.14, 213.97,\n",
" 367.19, 104.2, 78.65, 80.67, 158.84, 79.96, 58.98, 283.04, 166.48,\n",
" '20.9.46', 238.98, 81.46, 79.52, 75.92, 44.92, 255.4, 161.98,\n",
" 133.68, 52.42, 85.36, 55.5, 266.18, 162.38, 166.58, 133.56, 133,\n",
" 81.76, 133.98, 48.16, 84.25, 20.62, 20.78, 21.38, 24.8, 54.58,\n",
" 56.45, 26.7, 84.02, 81.28, 82.28, 50.18, 166.02, 166.42, 84.38,\n",
" 51.4, 24.62, 24.62, 70, 68.3, 68.9, 25.22, 27.32, 25.9, 26.06,\n",
" 70.32, 121.32, 69.6, 139.83, 88.9, 417, 164.75, 253.8, 77.54,\n",
" 157.76, 309.58], dtype=object),\n",
" array([660, 871, 908, 1140, 61, 62, 150.5, 134.22, 132.34, 164.94, 196.1,\n",
" 156.44, 121.32, 218.44, 137.9, 85.22, 217.18, 138.41, 83.75,\n",
" 300.35, 250.44, 137.77, 211.38, 302.38, 294.34, 195.72, 272.6,\n",
" 165.26, 168.53, 80.68, 26.014, 3.06, 68.69, 152.5, 148.75, 242.66,\n",
" 302.38, 192.35, 90, 282, 186, 251.6, 358.79, 86.44, 134.39, 114,\n",
" 112, 62, 85.27, 25.26, 20.8, 119.72, 190, 114, 62, 209.58, 169.83,\n",
" 475, 339, 376, 282, 188, 23.15, 23.15, 17.86, 75.91, 62, 188, 188,\n",
" 58.14, 21.19, 25.7, 120.1, 0, 183.91, 117.48, 64.69, 14.27, 18.21,\n",
" 132.88, 62, 62, 3.48, 3.19, 127.59, 24.95, 107.35, 61.5, 26.16,\n",
" 15.14, 20.07, 15.31, 81.41, 19.35, 13.85, 133.89, 127.81, 164.34,\n",
" 24.78, 142.46, 28.89, 88.7, 142.06, 27.1, 26.09, 28.87, 249.22,\n",
" 51.36, 16.26, 26.3, 20.66, 17.78, 21.22, 20.44, 15.44, 20.08,\n",
" 22.37, 20.88, 81.77, 137.64, 84.83, 53.3, 28.45, 24.04, 91.32,\n",
" 88.07, 92.33, 88.77, 24.82, 22.72, 25.43, 24.43, 88.26, 139.22,\n",
" 89.39, 171.22, 25.83, 25.86, 56.21, 23.58, 141.18, 89.92, 86.82,\n",
" 28.2, 26.77, 25.68, 26.48, 90.61, 108.7, 89.36, 27.61, 15.5, 26.27,\n",
" 25.64, 25.41, 23.45, 26.94, 91.06, 19.43, 24.12, 22.99, 24.22,\n",
" 26.94, 24.08, 91.46, 89.08, 52.99, 24.44, 22.08, 21.52, 20.56,\n",
" 18.72, 15.67, 69.62, 90.66, 46.66, 23.5, 13.8, 10.4, 22.9, 46.22,\n",
" 21.52, 26.1, 21.12, 20.39, 15.78, 23.38, 138.63, 119.52, 37.43,\n",
" 25.22, 25.87, 117.36, 87.34, 25.22, 138.24, 23.68, 43.39, 15.02,\n",
" 28.46, 23.83, 87.52, 21.12, 27.38, 26.08, 22.88, 18.34, 11.16,\n",
" 28.45, 14.82, 16.64, 13.32, 11.15, 15.1, 13.27, 11.75, 10.99,\n",
" 10.35, 9.76, 9.62, 9.49, 8.58, 10.55, 92.33, 92.33, 23.21, 23.21,\n",
" 18.92, 142.46, 27.99, 28.87, 15.82, 22.67, 16.79, 9.79, 9.6, 9.72,\n",
" 55.83, 90.05, 143.45, 20.95, 24.48, 24.48, 23.18, 17.92, 12.7,\n",
" 11.54, 10.79, 11.11, 7.1, 8.64, 9.99, 9.67, 137.01, 24.82, 19.4,\n",
" 12.08, 13.56, 8.13, 8.03, 8.24, 10.97, 9.27, 9.55, 14.33, 21.25,\n",
" 10.5, 12, 15.81, 173.13, 273.83, 106, 18.83, 83.98, 21.24, 20.23,\n",
" 16.27, 59.05, 23.98, 25.83, 19.41, 81.77, 86.9, 84.58, 20.63,\n",
" 84.77, 80.9, 24.42, 54.39, 188, 114, 62, 63, 148, 70, 62, 190, 171,\n",
" 188, 146, 31, 0, 0, 0, 75.78, 72.57, 269.49, 153.97, 293.89,\n",
" 115.73, 38.65, 10.82, 11, 74.76, 77.53, 23.93, 23.53, 21.15, 15.55,\n",
" 22.1, 22.37, 20.67, 19.66, 21.6, 23.64, 20.88, 21.98, 89.37, 23.98,\n",
" 25.04, 89.14, 25.93, 86.84, 22.18, 23.78, 24.52, 25.47, 89.77,\n",
" 75.8, 81.69, 87.93, 87.87, 19.12, 93.88, 122.28, 22.48, 119.88,\n",
" 383.53, 90.38, 169.25, 209.91, 235.5, 80.27, 22.77, 92.54, 22.77,\n",
" 22.77, 52.37, 209.7, 172.14, 210.77, 22.37, 57.37, 70.45, 167.25],\n",
" dtype=object)]"
]
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hrH37JLQTv_e"
},
"source": [
"# VERIFIKASI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "G06M4MuVULL4"
},
"source": [
"## Fungsi _private_ `_have_invalid()`\n",
"\n",
"Menjawab: Apakah `array` 1D ini memiliki data yang tidak bisa diubah ke dalam bentuk `check`?"
]
},
{
"cell_type": "code",
"metadata": {
"id": "TUzEviPETlum",
"outputId": "ce6ae832-9e41-4b1c-893e-a1d3897d917f",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"array = _get_data_allyear(SINGLE_DATASET, data_format='uma.debit')\n",
"print(f'shape = {array.shape}; type = {array.dtype}')"
],
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_data_allyear is deprecated, use _get_data_all_year instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"shape = (4018,); type = object\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "11SsglXPUk_M",
"outputId": "b28bbbca-f628-43ac-c17a-db324f0bc408",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_have_invalid(array, check=float)"
],
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _have_invalid is deprecated, use have_invalid instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"True"
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QhK43kUFVUaX"
},
"source": [
"## Fungsi _private_ `_get_invalid()`\n",
"\n",
"Tujuan: Memperoleh nilai _invalid_ beserta indexnya dalam bentuk `dictionary`"
]
},
{
"cell_type": "code",
"metadata": {
"id": "0ftKiz0fVTem",
"outputId": "de6a1d42-522f-42bc-be99-e225487b5680",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_get_invalid(array, check=float)"
],
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-2-23e254b88fe0>:27: DeprecationWarning: _get_invalid is deprecated, use _get_invalid_elements_indices instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"defaultdict(list, {'20.9.46': [309], 'NaN': [789], 'tad': [2974]})"
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "JFvqS43jWWeU"
},
"source": [
"## Fungsi _private_ `_check_invalid()`\n",
"\n",
"Tujuan: Memeriksa `array` memiliki nilai _invalid_, jika iya, apa saja?"
]
},
{
"cell_type": "code",
"metadata": {
"id": "_vNsb27BWgXN",
"outputId": "cc69fe48-9876-4624-842f-d183b716bd48",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"_check_invalid(array, validation_func=float)"
],
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"defaultdict(list, {'20.9.46': [309], 'NaN': [789], 'tad': [2974]})"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "arw-WniZWkL0",
"outputId": "3a666b95-477e-4cc3-f092-11f93d6b58e6",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 81
}
},
"source": [
"pd.DataFrame(_)"
],
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 20.9.46 NaN tad\n",
"0 309 789 2974"
],
"text/html": [
"\n",
" <div id=\"df-a204c677-b4b0-41e6-881d-e0ba81c00b1e\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>20.9.46</th>\n",
" <th>NaN</th>\n",
" <th>tad</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>309</td>\n",
" <td>789</td>\n",
" <td>2974</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a204c677-b4b0-41e6-881d-e0ba81c00b1e')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-a204c677-b4b0-41e6-881d-e0ba81c00b1e button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-a204c677-b4b0-41e6-881d-e0ba81c00b1e');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"summary": "{\n \"name\": \"pd\",\n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"20.9.46\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 309,\n \"max\": 309,\n \"num_unique_values\": 1,\n \"samples\": [\n 309\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"NaN\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 789,\n \"max\": 789,\n \"num_unique_values\": 1,\n \"samples\": [\n 789\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"tad\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 2974,\n \"max\": 2974,\n \"num_unique_values\": 1,\n \"samples\": [\n 2974\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 16
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "t8BYreReXI87"
},
"source": [
"# Penggunaan dalam folder"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "RnF3yQuOXNir"
},
"source": [
"## Fungsi _public_ `read_folder()`\n",
"\n",
"Tujuan: Membaca seluruh berkas excel di dalam folder yang mengikuti pola `pattern`, dan membaca isi berkas, kemudian menggabungkan seluruh hasil bacaan dalam bentuk `dictionary`."
]
},
{
"cell_type": "code",
"metadata": {
"id": "fXlcdHtEXMtw",
"outputId": "b279484e-3d8a-448d-879f-dd306648a73c",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"data, invalid = read_folder(DRIVE_DATASET_PATH, filename_pattern='hujan_*', data_format='uma.hujan', station_name_prefix='h_', check_for_invalid_data=True)"
],
"execution_count": 17,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"2024-04-13 23:36:47,589 - INFO - Found 8 file(s)\n",
"2024-04-13 23:36:47,593 - INFO - :: 0:\thujan_gardu_tanjak_1998_2008.xls\n",
"2024-04-13 23:36:49,840 - INFO - :: 1:\thujan_gunung_tunggal_1998_2008.xls\n",
"2024-04-13 23:36:52,125 - INFO - :: 2:\thujan_bd_pamarayan_1998_2008.xls\n",
"2024-04-13 23:36:53,982 - INFO - :: 3:\thujan_pasir_ona_1998_2008.xls\n",
"2024-04-13 23:36:55,738 - INFO - :: 4:\thujan_bojong_manik_1998_2008.xls\n",
"2024-04-13 23:36:58,895 - INFO - :: 5:\thujan_sampang_peundeuy_1998_2008.xls\n",
"2024-04-13 23:37:00,712 - INFO - :: 6:\thujan_ciminyak_cilaki_1998_2008.xls\n",
"2024-04-13 23:37:02,528 - INFO - :: 7:\thujan_cimarga_1998_2008.xls\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "jgImjlYoXuCl",
"outputId": "8e8786a5-10c2-4fe6-bbfd-417f87363d0d",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
}
},
"source": [
"pd.DataFrame(invalid).T"
],
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" - \\\n",
"h_gardu_tanjak [0, 1, 3, 4, 5, 8, 11, 12, 17, 19, 20, 22, 45,... \n",
"h_gunung_tunggal [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16,... \n",
"h_bd_pamarayan [0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15... \n",
"h_pasir_ona [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 14, 17, 18... \n",
"h_bojong_manik [0, 1, 3, 4, 5, 6, 8, 9, 11, 14, 16, 17, 19, 2... \n",
"h_sampang_peundeuy [2, 3, 4, 5, 16, 17, 18, 19, 20, 21, 22, 24, 2... \n",
"h_ciminyak_cilaki [0, 2, 3, 4, 5, 7, 8, 10, 11, 12, 13, 15, 17, ... \n",
"h_cimarga [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14,... \n",
"\n",
" NaN \n",
"h_gardu_tanjak NaN \n",
"h_gunung_tunggal NaN \n",
"h_bd_pamarayan [211, 576] \n",
"h_pasir_ona NaN \n",
"h_bojong_manik [2558] \n",
"h_sampang_peundeuy [0, 1] \n",
"h_ciminyak_cilaki NaN \n",
"h_cimarga NaN "
],
"text/html": [
"\n",
" <div id=\"df-fdbf9cf1-c960-4aec-901f-c0308709b347\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>-</th>\n",
" <th>NaN</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>h_gardu_tanjak</th>\n",
" <td>[0, 1, 3, 4, 5, 8, 11, 12, 17, 19, 20, 22, 45,...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_gunung_tunggal</th>\n",
" <td>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16,...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_bd_pamarayan</th>\n",
" <td>[0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15...</td>\n",
" <td>[211, 576]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_pasir_ona</th>\n",
" <td>[0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 14, 17, 18...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_bojong_manik</th>\n",
" <td>[0, 1, 3, 4, 5, 6, 8, 9, 11, 14, 16, 17, 19, 2...</td>\n",
" <td>[2558]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_sampang_peundeuy</th>\n",
" <td>[2, 3, 4, 5, 16, 17, 18, 19, 20, 21, 22, 24, 2...</td>\n",
" <td>[0, 1]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_ciminyak_cilaki</th>\n",
" <td>[0, 2, 3, 4, 5, 7, 8, 10, 11, 12, 13, 15, 17, ...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h_cimarga</th>\n",
" <td>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14,...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-fdbf9cf1-c960-4aec-901f-c0308709b347')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-fdbf9cf1-c960-4aec-901f-c0308709b347 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-fdbf9cf1-c960-4aec-901f-c0308709b347');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-b3621348-5b03-4dfe-bbbf-9e164bd98c7c\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-b3621348-5b03-4dfe-bbbf-9e164bd98c7c')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-b3621348-5b03-4dfe-bbbf-9e164bd98c7c button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"summary": "{\n \"name\": \"pd\",\n \"rows\": 8,\n \"fields\": [\n {\n \"column\": \"-\",\n \"properties\": {\n \"dtype\": \"object\",\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"NaN\",\n \"properties\": {\n \"dtype\": \"object\",\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 18
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "J55EY5cZX_ub",
"outputId": "794ee029-20e6-4185-80c5-ad85b9afb55c",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
}
},
"source": [
"pd.DataFrame(data, index=pd.date_range('19980101', '20081231'))"
],
"execution_count": 19,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" h_gardu_tanjak h_gunung_tunggal h_bd_pamarayan h_pasir_ona \\\n",
"1998-01-01 - - - - \n",
"1998-01-02 - - - - \n",
"1998-01-03 5 - 64 - \n",
"1998-01-04 - - - - \n",
"1998-01-05 - - - - \n",
"... ... ... ... ... \n",
"2008-12-27 14 15.7 - 7 \n",
"2008-12-28 - 19 - - \n",
"2008-12-29 12 21.7 2 11 \n",
"2008-12-30 10 17.5 4 21 \n",
"2008-12-31 13 29 6 4 \n",
"\n",
" h_bojong_manik h_sampang_peundeuy h_ciminyak_cilaki h_cimarga \n",
"1998-01-01 - NaN - - \n",
"1998-01-02 - NaN 7 - \n",
"1998-01-03 5 - - - \n",
"1998-01-04 - - - - \n",
"1998-01-05 - - - - \n",
"... ... ... ... ... \n",
"2008-12-27 12 21 - 36 \n",
"2008-12-28 10 15 - - \n",
"2008-12-29 7 50 - 32 \n",
"2008-12-30 6.05 22 - 28 \n",
"2008-12-31 - 18 - 39 \n",
"\n",
"[4018 rows x 8 columns]"
],
"text/html": [
"\n",
" <div id=\"df-ccba0b4c-c5f6-42db-a238-d3db3f5458a2\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>h_gardu_tanjak</th>\n",
" <th>h_gunung_tunggal</th>\n",
" <th>h_bd_pamarayan</th>\n",
" <th>h_pasir_ona</th>\n",
" <th>h_bojong_manik</th>\n",
" <th>h_sampang_peundeuy</th>\n",
" <th>h_ciminyak_cilaki</th>\n",
" <th>h_cimarga</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1998-01-01</th>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>NaN</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-02</th>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>NaN</td>\n",
" <td>7</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-03</th>\n",
" <td>5</td>\n",
" <td>-</td>\n",
" <td>64</td>\n",
" <td>-</td>\n",
" <td>5</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-04</th>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998-01-05</th>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-27</th>\n",
" <td>14</td>\n",
" <td>15.7</td>\n",
" <td>-</td>\n",
" <td>7</td>\n",
" <td>12</td>\n",
" <td>21</td>\n",
" <td>-</td>\n",
" <td>36</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-28</th>\n",
" <td>-</td>\n",
" <td>19</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>10</td>\n",
" <td>15</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-29</th>\n",
" <td>12</td>\n",
" <td>21.7</td>\n",
" <td>2</td>\n",
" <td>11</td>\n",
" <td>7</td>\n",
" <td>50</td>\n",
" <td>-</td>\n",
" <td>32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-30</th>\n",
" <td>10</td>\n",
" <td>17.5</td>\n",
" <td>4</td>\n",
" <td>21</td>\n",
" <td>6.05</td>\n",
" <td>22</td>\n",
" <td>-</td>\n",
" <td>28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-31</th>\n",
" <td>13</td>\n",
" <td>29</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>-</td>\n",
" <td>18</td>\n",
" <td>-</td>\n",
" <td>39</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4018 rows × 8 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ccba0b4c-c5f6-42db-a238-d3db3f5458a2')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-ccba0b4c-c5f6-42db-a238-d3db3f5458a2 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-ccba0b4c-c5f6-42db-a238-d3db3f5458a2');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-694a8256-f6a1-4bb9-b591-a952eefbd794\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-694a8256-f6a1-4bb9-b591-a952eefbd794')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-694a8256-f6a1-4bb9-b591-a952eefbd794 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"summary": "{\n \"name\": \"pd\",\n \"rows\": 4018,\n \"fields\": [\n {\n \"column\": \"h_gardu_tanjak\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 89,\n \"samples\": [\n 23.5,\n 28,\n 34\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_gunung_tunggal\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 135,\n \"samples\": [\n 10.5,\n 38,\n 85\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_bd_pamarayan\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 92,\n \"samples\": [\n 7,\n 8,\n 31\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_pasir_ona\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 145,\n \"samples\": [\n 5.9,\n 38,\n 46\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_bojong_manik\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 135,\n \"samples\": [\n 27.5,\n 50,\n 5.9\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_sampang_peundeuy\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 98,\n \"samples\": [\n 102,\n 52,\n 140\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_ciminyak_cilaki\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 109,\n \"samples\": [\n 122,\n 51,\n 35\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"h_cimarga\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 107,\n \"samples\": [\n 94,\n 29,\n 5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 19
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "MsL97BoMYShE"
},
"source": [
"# Changelog\n",
"\n",
"```\n",
"- 20240414 - 2.0.0 / 0.5.0 - Refactor hk43 (new function name & documentation)\n",
"- 20190926 - 1.0.0 - Initial\n",
"```\n",
"\n",
"#### Copyright &copy; 2019-2024 [Taruma Sakti Megariansyah](https://taruma.github.io)\n",
"\n",
"Source code in this notebook is licensed under a [MIT License](https://choosealicense.com/licenses/mit/). Data in this notebook is licensed under a [Creative Common Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/)."
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment