Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active April 13, 2024 07:21
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/6d48b3ec9d601019c15fb5833ae03730 to your computer and use it in GitHub Desktop.
Save taruma/6d48b3ec9d601019c15fb5833ae03730 to your computer and use it in GitHub Desktop.
taruma_hk88_ambil_dataset_harian.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk88_ambil_dataset_harian.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/6d48b3ec9d601019c15fb5833ae03730/taruma_hk88_ambil_dataset_harian.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cyMEUVNIy-7D"
},
"source": [
"Berdasarkan isu [#88](https://github.com/taruma/hidrokit/issues/88): **request: ambil dataset hujan harian**\n",
"\n",
"Referensi isu:\n",
"- `hidrokit.contrib.taruma.hk79` [#79](https://github.com/taruma/hidrokit/issues/79). \\([lihat notebook/manual](https://nbviewer.jupyter.org/gist/taruma/05dab67fac8313a94134ac02d0398897)\\). **request: ambil dataset hujan jam-jaman dari excel**\n",
"\n",
"Deskripsi permasalahan:\n",
"- Serupa dengan isu #79, akan tetapi dataset merupakan data harian.\n",
"- Mengambil dataset harian dalam excel yang berupa _pivot table_.\n",
"- Mengubah tabel tersebut ke dalam bentuk `pandas.DataFrame`, dengan baris menunjukkan observasi/kejadian dan kolom menunjukkan stasiun.\n",
"\n",
"Change Log:\n",
"- **New in Version 0.5.0.**: Refactor seluruh fungsi di hk88.\n",
"- ***New in version 0.4.0.*** [Isu #162](https://github.com/hidrokit/hidrokit/issues/162) Menambah fitur fungsi `read_workbook(...)` untuk membaca berkas tanpa perlu mengetahui nama _sheet_ dan membaca seluruh sheet kecuali yang _sheet_ berawalan `ignore_str='_'`.\n",
"- ***Breaking changes in version 0.4.0*** Bagi yang menggunakan luaran dengan argumen `as_df=False` akan memperoleh pesan error karena luaran sebelum versi 0.4.0 berupa `list`, sedangkan untuk versi 0.4.0 luaran berupa `dictionary`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zLMG_FiCz6A2"
},
"source": [
"# PERSIAPAN DAN DATASET"
]
},
{
"cell_type": "code",
"metadata": {
"id": "LFrXyfEdykhh",
"outputId": "1a979774-f621-4e5d-81e1-fe524dacec50",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"try:\n",
" import hidrokit\n",
"except ModuleNotFoundError:\n",
" !pip install hidrokit -q\n",
" import hidrokit\n",
"print(f'hidrokit version: {hidrokit.__version__}')"
],
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"hidrokit version: 0.4.1\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "LYTYboYS0Ph9"
},
"source": [
"# Unduh dataset\n",
"!wget -O sample.xlsx \"https://taruma.github.io/assets/hidrokit_dataset/hidrokit_daily_template.xlsx\" -q\n",
"FILE = 'sample.xlsx'"
],
"execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "MZ_I3qFS0bbV"
},
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
],
"execution_count": 15,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "6OxKS0piMAfN"
},
"source": [
"# KODE"
]
},
{
"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": "t_ZpdaU4Q-NW"
},
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ENMFCy1c2rnf"
},
"source": [
"from calendar import isleap\n",
"from typing import List, Union\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"\n",
"def _melt_to_year_vector(dataframe: pd.DataFrame, year: int) -> np.ndarray:\n",
" \"\"\"\n",
" Melt a pandas DataFrame to a 1D numpy array for a specific year.\n",
"\n",
" Args:\n",
" dataframe: The pandas DataFrame to melt.\n",
" year: The year to consider when melting the DataFrame.\n",
"\n",
" Returns:\n",
" A 1D numpy array representing the melted DataFrame for the specified year.\n",
" \"\"\"\n",
" if not isinstance(dataframe, pd.DataFrame):\n",
" raise ValueError(\"dataframe must be a pandas DataFrame.\")\n",
" if not isinstance(year, int):\n",
" raise ValueError(\"year must be an integer.\")\n",
"\n",
" _drop = [59, 60, 61, 123, 185, 278, 340]\n",
" _drop_leap = [60, 61, 123, 185, 278, 340]\n",
"\n",
" melted_data = dataframe.melt().drop(\"variable\", axis=1)\n",
" if isleap(year):\n",
" return melted_data[\"value\"].drop(_drop_leap).values\n",
" return melted_data[\"value\"].drop(_drop).values\n",
"\n",
"\n",
"def _generate_date_range_for_year(year):\n",
" \"\"\"Return DateTimeIndex object for one year.\n",
"\n",
" Args:\n",
" year (int): The year for which to generate the date range.\n",
"\n",
" Returns:\n",
" pd.DatetimeIndex: A DateTimeIndex object representing the date range for the specified year.\n",
" \"\"\"\n",
" start_date = pd.Timestamp(year, 1, 1)\n",
" end_date = pd.Timestamp(year + 1, 1, 1)\n",
" return pd.date_range(start_date, end_date, inclusive=\"left\")\n",
"\n",
"\n",
"def _create_yearly_dataframe(\n",
" dataframe: pd.DataFrame, year: int, station_name: str\n",
") -> pd.DataFrame:\n",
" \"\"\"\n",
" Create a DataFrame for one year.\n",
"\n",
" Parameters:\n",
" df (DataFrame): The original DataFrame.\n",
" year (int): The year to filter the DataFrame.\n",
" station_name (str): The name of the station.\n",
"\n",
" Returns:\n",
" DataFrame: A new DataFrame with data for the specified year and station.\n",
" \"\"\"\n",
" return pd.DataFrame(\n",
" data=_melt_to_year_vector(dataframe, year),\n",
" index=_generate_date_range_for_year(year),\n",
" columns=[station_name],\n",
" )\n",
"\n",
"\n",
"def _extract_data_from_sheet(\n",
" dataframe: pd.DataFrame, station: str, return_as_dataframe: bool = True\n",
") -> Union[pd.DataFrame, List[pd.DataFrame]]:\n",
" \"\"\"\n",
" Extracts data from a sheet in the given dataframe and returns it\n",
" as a dataframe or a list of dataframes.\n",
"\n",
" Parameters:\n",
" dataframe (pd.DataFrame): The dataframe containing the sheet data.\n",
" station (str): The name of the station.\n",
" return_as_dataframe (bool, optional): Whether to return the data\n",
" as a single dataframe or a list of dataframes. Defaults to True.\n",
"\n",
" Returns:\n",
" Union[pd.DataFrame, List[pd.DataFrame]]:\n",
" The extracted data as a dataframe or a list of dataframes.\n",
" \"\"\"\n",
" total_years = int(dataframe.iloc[0, 1])\n",
"\n",
" yearly_dataframes = []\n",
" for i in range(2, total_years * 33, 33):\n",
" current_year = int(dataframe.iloc[i, 1])\n",
" yearly_data = dataframe.iloc[i : i + 31, 4:16]\n",
" yearly_dataframe = _create_yearly_dataframe(yearly_data, current_year, station)\n",
" yearly_dataframes.append(yearly_dataframe)\n",
"\n",
" if return_as_dataframe:\n",
" return pd.concat(yearly_dataframes, sort=True)\n",
"\n",
" return yearly_dataframes\n",
"\n",
"\n",
"def read_hidrokit_workbook(\n",
" file_path, station_names=None, ignore_prefix=\"_\", return_as_dataframe=True\n",
"):\n",
" \"\"\"\n",
" Read data from an hidrokit Excel workbook.\n",
"\n",
" Parameters:\n",
" file_path (str): The path to the Excel workbook file.\n",
" station_names (list or str, optional): The names of the sheets to read.\n",
" If not provided, all sheets will be read.\n",
" ignore_prefix (str, optional): The prefix used to ignore sheets. Default is '_'.\n",
" return_as_dataframe (bool, optional): Whether to return the data as a pandas DataFrame.\n",
" Default is True.\n",
"\n",
" Returns:\n",
" dict or pandas.DataFrame: A dictionary containing the data from each sheet,\n",
" with sheet names as keys. If `return_as_dataframe` is True,\n",
" a pandas DataFrame is returned instead.\n",
"\n",
" \"\"\"\n",
"\n",
" excel_file = pd.ExcelFile(file_path)\n",
"\n",
" station_data = {}\n",
" all_sheet_names = excel_file.sheet_names\n",
" if station_names is None:\n",
" station_names = []\n",
" for sheet_name in all_sheet_names:\n",
" if not sheet_name.startswith(ignore_prefix):\n",
" station_names.append(sheet_name)\n",
" else:\n",
" station_names = (\n",
" [station_names] if isinstance(station_names, str) else station_names\n",
" )\n",
"\n",
" for station_name in station_names:\n",
" dataframe = excel_file.parse(sheet_name=station_name, header=None)\n",
" station_data[station_name] = _extract_data_from_sheet(dataframe, station_name)\n",
"\n",
" if return_as_dataframe:\n",
" return pd.concat(station_data.values(), sort=True, axis=1)\n",
"\n",
" return station_data\n",
"\n",
"\n",
"## Backward Compatibility (0.3.x - 0.4.x)\n",
"\n",
"\n",
"@deprecated(\"_melt_to_year_vector\")\n",
"def _melt_to_array(*args, **kwargs):\n",
" return _melt_to_year_vector(*args, **kwargs)\n",
"\n",
"\n",
"@deprecated(\"_generate_date_range_for_year\")\n",
"def _index_daily(*args, **kwargs):\n",
" return _generate_date_range_for_year(*args, **kwargs)\n",
"\n",
"\n",
"@deprecated(\"_create_yearly_dataframe\")\n",
"def _yearly_df(*args, **kwargs):\n",
" return _create_yearly_dataframe(*args, **kwargs)\n",
"\n",
"\n",
"@deprecated(\"_extract_data_from_sheet\")\n",
"def _data_from_sheet(*args, **kwargs):\n",
" return _extract_data_from_sheet(*args, **kwargs)\n",
"\n",
"\n",
"@deprecated(\"read_hidrokit_workbook\")\n",
"def read_workbook(io, stations=None, ignore_str=\"_\", as_df=True):\n",
" \"\"\"\n",
" Read data from an hidrokit Excel workbook.\n",
"\n",
" Parameters:\n",
" io (str): The path to the Excel workbook file.\n",
" stations (list or str, optional): The names of the sheets to read.\n",
" If not provided, all sheets will be read.\n",
" ignore_str (str, optional): The prefix used to ignore sheets. Default is '_'.\n",
" as_df (bool, optional): Whether to return the data as a pandas DataFrame.\n",
" Default is True.\n",
"\n",
" Returns:\n",
" dict or pandas.DataFrame: A dictionary containing the data from each sheet,\n",
" with sheet names as keys. If `as_df` is True,\n",
" a pandas DataFrame is returned instead.\n",
"\n",
" \"\"\"\n",
" return read_hidrokit_workbook(\n",
" file_path=io,\n",
" station_names=stations,\n",
" ignore_prefix=ignore_str,\n",
" return_as_dataframe=as_df,\n",
" )\n"
],
"execution_count": 22,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "WCvI1utFV8UN"
},
"source": [
"# PENERAPAN"
]
},
{
"cell_type": "code",
"metadata": {
"id": "0L_L1QJb0fVz",
"outputId": "580e63d0-c9ca-4133-cca4-becaf0eb933c",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"np.float = float # temporary fix 0.4.x\n",
"from hidrokit.contrib.taruma import hk79\n",
"import numpy as np\n",
"\n",
"\n",
"# Ambil informasi excel menggunakan modul .hk79\n",
"data_info = hk79._get_info(FILE, config_sheet='_INFO')\n",
"print(':: INFORMASI PADA BERKAS')\n",
"print(data_info)"
],
"execution_count": 23,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
":: INFORMASI PADA BERKAS\n",
"{'key': 'VALUE', 'n_stations': 2, 'stations': 'AURENE, TYBALT', 'source': 'RATA SUM', 'station_1_years': '2002, 2003, 2004', 'station_2_years': '2007, 2008'}\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "Pt2GkALg1fIp",
"outputId": "ab68db88-7524-4424-bc09-ded49bb50152",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"stations = data_info['stations'].replace(' ', '').split(',')\n",
"print('nama stasiun dalam berkas:', stations)"
],
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"nama stasiun dalam berkas: ['AURENE', 'TYBALT']\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cKPgxWR92BAC"
},
"source": [
"## Baca satu stasiun"
]
},
{
"cell_type": "code",
"metadata": {
"id": "sOSA67xI2PGt",
"outputId": "ae6bad18-f0e7-488b-e7d7-4825e9bdc75e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 397
}
},
"source": [
"aurene = read_workbook(FILE, ['AURENE'])\n",
"aurene.info()\n",
"aurene.head()"
],
"execution_count": 25,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-16-23e254b88fe0>:27: DeprecationWarning: read_workbook is deprecated, use read_hidrokit_workbook instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"DatetimeIndex: 1096 entries, 2002-01-01 to 2004-12-31\n",
"Freq: D\n",
"Data columns (total 1 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 AURENE 1096 non-null object\n",
"dtypes: object(1)\n",
"memory usage: 17.1+ KB\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" AURENE\n",
"2002-01-01 17.08\n",
"2002-01-02 16.28\n",
"2002-01-03 20.32\n",
"2002-01-04 18.34\n",
"2002-01-05 13.16"
],
"text/html": [
"\n",
" <div id=\"df-53e70cc0-4981-4dd2-95c0-feda2b848110\" 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>AURENE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>17.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-02</th>\n",
" <td>16.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-03</th>\n",
" <td>20.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-04</th>\n",
" <td>18.34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-05</th>\n",
" <td>13.16</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-53e70cc0-4981-4dd2-95c0-feda2b848110')\"\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-53e70cc0-4981-4dd2-95c0-feda2b848110 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-53e70cc0-4981-4dd2-95c0-feda2b848110');\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-20a462b8-8f02-4930-94fc-6c6ae1d956b3\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-20a462b8-8f02-4930-94fc-6c6ae1d956b3')\"\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-20a462b8-8f02-4930-94fc-6c6ae1d956b3 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",
"variable_name": "aurene",
"summary": "{\n \"name\": \"aurene\",\n \"rows\": 1096,\n \"fields\": [\n {\n \"column\": \"AURENE\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0,\n \"max\": 642.57,\n \"num_unique_values\": 741,\n \"samples\": [\n 51.72,\n 172.43,\n 82.19\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 25
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "biE_Koc56xHi"
},
"source": [
"## Baca lebih dari satu stasiun"
]
},
{
"cell_type": "code",
"metadata": {
"id": "PlUaXdWH2c11",
"outputId": "61e62ba3-7872-441a-e038-36f1efaca48e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 458
}
},
"source": [
"dataset = read_workbook(FILE, ['TYBALT', 'AURENE'])\n",
"dataset.sort_index()"
],
"execution_count": 26,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-16-23e254b88fe0>:27: DeprecationWarning: read_workbook is deprecated, use read_hidrokit_workbook instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
" TYBALT AURENE\n",
"2002-01-01 NaN 17.08\n",
"2002-01-02 NaN 16.28\n",
"2002-01-03 NaN 20.32\n",
"2002-01-04 NaN 18.34\n",
"2002-01-05 NaN 13.16\n",
"... ... ...\n",
"2008-12-27 134.83 NaN\n",
"2008-12-28 81.88 NaN\n",
"2008-12-29 20.14 NaN\n",
"2008-12-30 208.54 NaN\n",
"2008-12-31 208.14 NaN\n",
"\n",
"[1827 rows x 2 columns]"
],
"text/html": [
"\n",
" <div id=\"df-d6d5c785-8508-4645-a52e-f8dd5e60e1ab\" 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>TYBALT</th>\n",
" <th>AURENE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>NaN</td>\n",
" <td>17.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-02</th>\n",
" <td>NaN</td>\n",
" <td>16.28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-03</th>\n",
" <td>NaN</td>\n",
" <td>20.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-04</th>\n",
" <td>NaN</td>\n",
" <td>18.34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-05</th>\n",
" <td>NaN</td>\n",
" <td>13.16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-27</th>\n",
" <td>134.83</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-28</th>\n",
" <td>81.88</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-29</th>\n",
" <td>20.14</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-30</th>\n",
" <td>208.54</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-31</th>\n",
" <td>208.14</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1827 rows × 2 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-d6d5c785-8508-4645-a52e-f8dd5e60e1ab')\"\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-d6d5c785-8508-4645-a52e-f8dd5e60e1ab 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-d6d5c785-8508-4645-a52e-f8dd5e60e1ab');\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-4d29d804-b9ee-4878-a89d-f6e84106b949\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-4d29d804-b9ee-4878-a89d-f6e84106b949')\"\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-4d29d804-b9ee-4878-a89d-f6e84106b949 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\": \"dataset\",\n \"rows\": 1827,\n \"fields\": [\n {\n \"column\": \"TYBALT\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0,\n \"max\": 804,\n \"num_unique_values\": 517,\n \"samples\": [\n 201.57,\n 34.36,\n 16.26\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"AURENE\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0,\n \"max\": 642.57,\n \"num_unique_values\": 741,\n \"samples\": [\n 51.72,\n 172.43,\n 82.19\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 26
}
]
},
{
"cell_type": "markdown",
"source": [
"## FUNGSI `read_hidrokit_workbook(io, ...)`\n",
"\n",
"Function: `read_hidrokit_workbook(file_path, station_names=None, ignore_prefix=\"_\", return_as_dataframe=True)`\n",
"\n",
"```\n",
"Read data from an Excel workbook.\n",
"\n",
"Parameters:\n",
" file_path (str): The path to the Excel workbook file.\n",
" station_names (list or str, optional): The names of the sheets to read.\n",
" If not provided, all sheets will be read.\n",
" ignore_prefix (str, optional): The prefix used to ignore sheets. Default is '_'.\n",
" return_as_dataframe (bool, optional): Whether to return the data as a pandas DataFrame.\n",
" Default is True.\n",
"\n",
"Returns:\n",
" dict or pandas.DataFrame: A dictionary containing the data from each sheet,\n",
" with sheet names as keys. If `return_as_dataframe` is True,\n",
" a pandas DataFrame is returned instead.\n",
"```\n",
"\n",
"Catatan: Di hidrokit 0.5.x, fungsi `read_workbook(...)` diperbarui menjadi `read_hidrokit_workbook(...)` agar lebih jelas dan mudah dibaca."
],
"metadata": {
"id": "hAZpB2UVyJvR"
}
},
{
"cell_type": "code",
"source": [
"read_hidrokit_workbook(FILE)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "42vGFGsKyI8a",
"outputId": "c67cb88d-82f8-4afc-f3c6-d9239ddf5b7b"
},
"execution_count": 27,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" AURENE TYBALT\n",
"2002-01-01 17.08 NaN\n",
"2002-01-02 16.28 NaN\n",
"2002-01-03 20.32 NaN\n",
"2002-01-04 18.34 NaN\n",
"2002-01-05 13.16 NaN\n",
"... ... ...\n",
"2008-12-27 NaN 134.83\n",
"2008-12-28 NaN 81.88\n",
"2008-12-29 NaN 20.14\n",
"2008-12-30 NaN 208.54\n",
"2008-12-31 NaN 208.14\n",
"\n",
"[1827 rows x 2 columns]"
],
"text/html": [
"\n",
" <div id=\"df-1a677f16-00e8-4622-97ed-8471942a54b9\" 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>AURENE</th>\n",
" <th>TYBALT</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2002-01-01</th>\n",
" <td>17.08</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-02</th>\n",
" <td>16.28</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-03</th>\n",
" <td>20.32</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-04</th>\n",
" <td>18.34</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-05</th>\n",
" <td>13.16</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-27</th>\n",
" <td>NaN</td>\n",
" <td>134.83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-28</th>\n",
" <td>NaN</td>\n",
" <td>81.88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-29</th>\n",
" <td>NaN</td>\n",
" <td>20.14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-30</th>\n",
" <td>NaN</td>\n",
" <td>208.54</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2008-12-31</th>\n",
" <td>NaN</td>\n",
" <td>208.14</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1827 rows × 2 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-1a677f16-00e8-4622-97ed-8471942a54b9')\"\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-1a677f16-00e8-4622-97ed-8471942a54b9 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-1a677f16-00e8-4622-97ed-8471942a54b9');\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-b64b57df-4ea1-45ee-aecf-086dcf3e03da\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-b64b57df-4ea1-45ee-aecf-086dcf3e03da')\"\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-b64b57df-4ea1-45ee-aecf-086dcf3e03da 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\": \"read_hidrokit_workbook(FILE)\",\n \"rows\": 1827,\n \"fields\": [\n {\n \"column\": \"AURENE\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0,\n \"max\": 642.57,\n \"num_unique_values\": 741,\n \"samples\": [\n 51.72,\n 172.43,\n 82.19\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"TYBALT\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0,\n \"max\": 804,\n \"num_unique_values\": 517,\n \"samples\": [\n 201.57,\n 34.36,\n 16.26\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 27
}
]
},
{
"cell_type": "code",
"source": [
"read_hidrokit_workbook(FILE, return_as_dataframe=False)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "r0ILB-kt2bC_",
"outputId": "82f37045-97ed-446b-cdcc-08095b9f81af"
},
"execution_count": 29,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'AURENE': AURENE\n",
" 2002-01-01 17.08\n",
" 2002-01-02 16.28\n",
" 2002-01-03 20.32\n",
" 2002-01-04 18.34\n",
" 2002-01-05 13.16\n",
" ... ...\n",
" 2004-12-27 454.75\n",
" 2004-12-28 69.75\n",
" 2004-12-29 189.39\n",
" 2004-12-30 166.39\n",
" 2004-12-31 133.99\n",
" \n",
" [1096 rows x 1 columns],\n",
" 'TYBALT': TYBALT\n",
" 2007-01-01 201.92\n",
" 2007-01-02 255.38\n",
" 2007-01-03 130.84\n",
" 2007-01-04 17.96\n",
" 2007-01-05 19.12\n",
" ... ...\n",
" 2008-12-27 134.83\n",
" 2008-12-28 81.88\n",
" 2008-12-29 20.14\n",
" 2008-12-30 208.54\n",
" 2008-12-31 208.14\n",
" \n",
" [731 rows x 1 columns]}"
]
},
"metadata": {},
"execution_count": 29
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "z0Dp41jW5CHa"
},
"source": [
"# Changelog\n",
"\n",
"```\n",
"- 20240413 - 2.0.0 / 0.5.0 - Refactor hk88, new functions name.\n",
"- 20220402 - 1.1.1 - Change 0.3.7 to 0.4.0\n",
"- 20220318 - 1.1.0 - Improve read_workbook(...) function Issue #162\n",
"- 20191217 - 1.0.1 - Fix read_workbook() issue#95\n",
"- 20191213 - 1.0.0 - Initial\n",
"```\n",
"\n",
"#### Copyright &copy; 2022 [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/).\n"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment