Skip to content

Instantly share code, notes, and snippets.

@taruma
Last active April 14, 2024 05:39
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/05dab67fac8313a94134ac02d0398897 to your computer and use it in GitHub Desktop.
Save taruma/05dab67fac8313a94134ac02d0398897 to your computer and use it in GitHub Desktop.
taruma_hk79_baca_excel_jamjaman.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "taruma_hk79_baca_excel_jamjaman.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/05dab67fac8313a94134ac02d0398897/taruma_hk79_baca_excel_jamjaman.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QlYJu4L1xpaL"
},
"source": [
"Berdasarkan isu [#79](https://github.com/taruma/hidrokit/issues/79): __request: ambil dataset hujan jam-jaman dari excel__\n",
"\n",
"Referensi isu:\n",
"- `hidrokit.contrib.taruma.hk43` [#43](https://github.com/taruma/hidrokit/issues/43). \\([view notebook / manual](https://nbviewer.jupyter.org/gist/taruma/a9dd4ea61db2526853b99600909e9c50)\\). (Menggunakan fungsi `_get_years()` untuk memperoleh `list` tahun pada berkas excel.\n",
"\n",
"Deskripsi permasalahan:\n",
"- Membaca data jam-jaman dari excel\n",
"- Data dalam excel berupa _pivot table_\n",
"- Ubah _pivot table_ ke _regular table_\n",
"- Mengubah tabel tersebut menjadi `pandas.DataFrame`\n",
"\n",
"Strategi penyelesaian masalah:\n",
"- Periksa _sheet_ didalam berkas excel\n",
"- Baca metadata/konfigurasi excel (nama stasiun)\n",
"- Untuk setiap _sheet_ dengan digit tahun, baca setiap _sheet_ (menggunakan `hk43._get_years()`)\n",
"- Dalam _sheet_ tunggal:\n",
" - Baca informasi tahun di lembar aktif\n",
" - Membaca dan mempraproses dataset setiap bulannya\n",
" - Menggabungkan hasil pengubahan pivot ke tabel reguler\n",
" - Menggabungkan tabel reguler dalam satu tahun\n",
"- Menggabungkan tabel setiap tahun menjadi satu `pandas.DataFrame`\n",
"\n",
"Catatan:\n",
"Untuk prapemrosesan tabel seperti (cek data yang hilang, dlsbnya) akan dikembangkan dengan modul yang terpisah karena beberapa fungsi sudah tersedia di modul `hidrokit.contrib.taruma.hk73` (untuk mengolah berkas dari bmkg)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rLLirn8y6FRB"
},
"source": [
"# PERSIAPAN DAN DATASET"
]
},
{
"cell_type": "code",
"metadata": {
"id": "_q5GFz-NwQpx"
},
"source": [
"# Download sample excel\n",
"!wget -O sample.xlsx \"https://taruma.github.io/assets/hidrokit_dataset/hidrokit_hourly_template.xlsx\" -q"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "__pTGKmWwkuA"
},
"source": [
"# Import library\n",
"import pandas as pd\n",
"import numpy as np"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "zFd-3lFW6SIa"
},
"source": [
"# KODE"
]
},
{
"cell_type": "code",
"source": [
"def extract_years_from_excel(file_path):\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)"
],
"metadata": {
"id": "24mCxBY3DTE_"
},
"execution_count": 10,
"outputs": []
},
{
"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": "syotTOSIGdwV"
},
"execution_count": 11,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "xw79uxePB_k5"
},
"source": [
"from calendar import monthrange\n",
"\n",
"# ref: https://www.reddit.com/r/learnpython/comments/485h1p/\n",
"from collections.abc import Sequence\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"def _index_hourly(year, freq=\"60min\"):\n",
" \"\"\"\n",
" Create a DatetimeIndex with specific year or [year_start, year_end].\n",
"\n",
" Parameters:\n",
" year (int or tuple): The year or range of years to create the index for.\n",
" If an int is provided, the index will be created for that specific year.\n",
" If a tuple is provided, the index will be created for the range of years\n",
" specified by the tuple (inclusive).\n",
" freq (str, optional): The frequency of the index. Defaults to \"60min\".\n",
"\n",
" Returns:\n",
" pd.DatetimeIndex: The generated DatetimeIndex.\n",
"\n",
" \"\"\"\n",
" if isinstance(year, Sequence):\n",
" year_start, year_end = year\n",
" else:\n",
" year_start, year_end = year, year\n",
"\n",
" period = f\"{year_start}0101 00:00,{year_end}1231 23:00\".split(\",\")\n",
" return pd.date_range(*period, freq=freq)\n",
"\n",
"\n",
"def _melt_to_array(dataframe):\n",
" \"\"\"\n",
" Convert a DataFrame to a 1-dimensional array by melting it and extracting the 'value' column.\n",
"\n",
" Parameters:\n",
" df (pandas.DataFrame): The DataFrame to be converted.\n",
"\n",
" Returns:\n",
" numpy.ndarray: A 1-dimensional array containing the values\n",
" from the 'value' column of the melted DataFrame.\n",
" \"\"\"\n",
" return dataframe.melt().drop(\"variable\", axis=1)[\"value\"].values\n",
"\n",
"\n",
"def _get_array_in_month(dataframe, year, month):\n",
" \"\"\"\n",
" Get an array of data for a specific year and month from a dataframe.\n",
"\n",
" Parameters:\n",
" dataframe (pandas.DataFrame): The input dataframe.\n",
" year (int): The year.\n",
" month (int): The month.\n",
"\n",
" Returns:\n",
" numpy.ndarray: The array of data for the specified year and month.\n",
" \"\"\"\n",
" n_days = monthrange(year, month)[1]\n",
" mask_month = slice(None, n_days)\n",
" df_month = dataframe.iloc[mask_month, :].T\n",
" return _melt_to_array(df_month)\n",
"\n",
"\n",
"def _get_array_in_year(df, year):\n",
" \"\"\"\n",
" Get an array of data for a specific year from a DataFrame.\n",
"\n",
" Parameters:\n",
" - df (pandas.DataFrame): The DataFrame containing the data.\n",
" - year (int): The year for which the data is to be extracted.\n",
"\n",
" Returns:\n",
" - numpy.ndarray: The array of data for the specified year.\n",
" \"\"\"\n",
" n_rows, _ = df.shape\n",
"\n",
" # configuration (view the excel)\n",
" n_month = 1 # number of row to monthID\n",
" n_gap = 2 # number of row between month pivot table\n",
" n_lines = 31 + n_gap # number of row each month\n",
"\n",
" data = []\n",
" for row in range(1, n_rows, n_lines):\n",
" mask_start = row + n_month\n",
" mask_end = row + n_lines\n",
"\n",
" month = df.iloc[mask_start, 1]\n",
" mask_row = slice(mask_start, mask_end)\n",
"\n",
" df_month = df.iloc[mask_row, 4:]\n",
" array_month = _get_array_in_month(df_month, year, month)\n",
" data.append(array_month)\n",
"\n",
" return np.hstack(data)\n",
"\n",
"\n",
"def get_info(file, config_sheet=None):\n",
" \"\"\"\n",
" Retrieves information from an Excel file.\n",
"\n",
" Args:\n",
" file (str): The path to the Excel file.\n",
" config_sheet (str, optional): The name of the sheet to read from.\n",
" If not provided, the first sheet will be used.\n",
"\n",
" Returns:\n",
" dict: A dictionary containing the information retrieved from the Excel file.\n",
" The keys are the lowercase values from the first column,\n",
" and the values are the corresponding values from the second column.\n",
" \"\"\"\n",
" excel = pd.ExcelFile(file)\n",
" first_sheet = excel.sheet_names[0]\n",
" config_sheet = first_sheet if config_sheet is None else config_sheet\n",
"\n",
" df = pd.read_excel(excel, sheet_name=config_sheet, header=None, usecols=\"A:B\")\n",
" info = {}\n",
"\n",
" for index, _ in df.iterrows():\n",
" key = df.iloc[index, 0].lower()\n",
" value = df.iloc[index, 1]\n",
" info[str(key)] = value\n",
"\n",
" return info\n",
"\n",
"\n",
"@deprecated(\"get_info\")\n",
"def _get_info(file, config_sheet=None):\n",
" return get_info(file, config_sheet=config_sheet)\n",
"\n",
"\n",
"def read_excel_hourly(file, station=None):\n",
" \"\"\"\n",
" Read hourly data from an Excel file.\n",
"\n",
" Parameters:\n",
" file (str): The path to the Excel file.\n",
" station (str, optional): The name of the station. Defaults to None.\n",
"\n",
" Returns:\n",
" pandas.DataFrame: A DataFrame containing the hourly data.\n",
"\n",
" \"\"\"\n",
" excel = pd.ExcelFile(file)\n",
"\n",
" # CONFIG\n",
" years = extract_years_from_excel(excel)\n",
" station = \"NA\" if station is None else station\n",
"\n",
" # READ DATA\n",
" data = []\n",
" for year in years:\n",
" sheet = pd.read_excel(\n",
" excel, sheet_name=str(year), header=None, nrows=396, usecols=\"A:AB\"\n",
" )\n",
" array = _get_array_in_year(sheet, year)\n",
" df_year = pd.DataFrame(data=array, columns=[station], index=_index_hourly(year))\n",
" data.append(df_year)\n",
"\n",
" return pd.concat(data, axis=0)\n"
],
"execution_count": 12,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "XzODOG3hWvqX"
},
"source": [
"# FUNGSI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "kRYwmWihXYfk"
},
"source": [
"## Fungsi _private_ `_index_hourly(year, freq='60min')`\n",
"\n",
"Tujuan: membuat index menggunakan perintah `pd.date_range()` dengan input `year` yang berupa bilangan ataupun _sequence_."
]
},
{
"cell_type": "code",
"metadata": {
"id": "Iz13fHtnWu9O",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "2d986e62-fbc0-427a-e55a-01624cd9901a"
},
"source": [
"_index_hourly(2000) # jika bilangan harus dalam bentuk integer"
],
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 01:00:00',\n",
" '2000-01-01 02:00:00', '2000-01-01 03:00:00',\n",
" '2000-01-01 04:00:00', '2000-01-01 05:00:00',\n",
" '2000-01-01 06:00:00', '2000-01-01 07:00:00',\n",
" '2000-01-01 08:00:00', '2000-01-01 09:00:00',\n",
" ...\n",
" '2000-12-31 14:00:00', '2000-12-31 15:00:00',\n",
" '2000-12-31 16:00:00', '2000-12-31 17:00:00',\n",
" '2000-12-31 18:00:00', '2000-12-31 19:00:00',\n",
" '2000-12-31 20:00:00', '2000-12-31 21:00:00',\n",
" '2000-12-31 22:00:00', '2000-12-31 23:00:00'],\n",
" dtype='datetime64[ns]', length=8784, freq='60T')"
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "dN9idPu5X5pS",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "92ce3513-e717-4d3b-ca37-d0d01bc3e355"
},
"source": [
"_index_hourly(['2000', 2001]) # jika dalam seq-object bisa berupa integer atau string"
],
"execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 01:00:00',\n",
" '2000-01-01 02:00:00', '2000-01-01 03:00:00',\n",
" '2000-01-01 04:00:00', '2000-01-01 05:00:00',\n",
" '2000-01-01 06:00:00', '2000-01-01 07:00:00',\n",
" '2000-01-01 08:00:00', '2000-01-01 09:00:00',\n",
" ...\n",
" '2001-12-31 14:00:00', '2001-12-31 15:00:00',\n",
" '2001-12-31 16:00:00', '2001-12-31 17:00:00',\n",
" '2001-12-31 18:00:00', '2001-12-31 19:00:00',\n",
" '2001-12-31 20:00:00', '2001-12-31 21:00:00',\n",
" '2001-12-31 22:00:00', '2001-12-31 23:00:00'],\n",
" dtype='datetime64[ns]', length=17544, freq='60T')"
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HR50WxV0YS6e"
},
"source": [
"## Fungsi _private_ `_melt_to_array(df)`\n",
"\n",
"Tujuan: perintah `df.melt().drop('variable', axis=1)['value'].values`\n",
"\n",
"Contoh `pd.melt` bisa lihat pada manual [hk43](https://nbviewer.jupyter.org/gist/taruma/a9dd4ea61db2526853b99600909e9c50)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F6LCRneQYodb"
},
"source": [
"## Fungsi _private_ `_get_array_in_month(df, year, month)`\n",
"\n",
"Tujuan: mengambil pivot tabel satu bulan dan mengubahnya (_melt_) ke bentuk tabel biasa."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Xc1zXpIXZJTP"
},
"source": [
"## Fungsi _private_ `_get_array_in_year(df, year)`\n",
"\n",
"Tujuan: serupa dengan `_get_array_in_month()`, fungsi ini mengambil seluruh informasi pada _sheet_ tunggal."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F7AXuu2JZkOa"
},
"source": [
"## Fungsi _private_ `_get_info(file, config_sheet=None)`\n",
"\n",
"Tujuan: mengambil nilai pada _sheet_ pengaturan (_sheet_ pertama pada file) dan mengubahnya ke dalam bentuk `dictionary`."
]
},
{
"cell_type": "code",
"metadata": {
"id": "FFAqYl0FZi8W",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "b2938fa7-7421-4848-b8c4-be101e7afd8a"
},
"source": [
"info_file = _get_info('sample.xlsx', config_sheet='_INFO')\n",
"info_file"
],
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-11-23e254b88fe0>:27: DeprecationWarning: _get_info is deprecated, use get_info instead\n",
" warnings.warn(\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'key': 'VALUE', 'station_name': 'Aurene'}"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "LGH5Q8B9aChT",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "41a414dc-a673-4288-8283-cef51b9fffaf"
},
"source": [
"info_file['station_name']"
],
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'Aurene'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 16
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "PHb8kiqIbXBC"
},
"source": [
"# PENERAPAN"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "JQ25V3gmaRCz"
},
"source": [
"## Fungsi _public_ `read_excel_hourly(file, station=None)`\n",
"\n",
"Tujuan: membaca data jam-jaman yang terdapat pada file lalu mengubahnya ke dalam bentuk `pandas.DataFrame` dengan index yang sesuai dengan tahun kejadiannya."
]
},
{
"cell_type": "code",
"metadata": {
"id": "_ZgcqRAmOHvn",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"outputId": "6e7f51c6-d320-40c4-f1c6-deaf2cade111"
},
"source": [
"data = read_excel_hourly('sample.xlsx', station=info_file['station_name'])\n",
"data"
],
"execution_count": 17,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Aurene\n",
"2000-01-01 00:00:00 -\n",
"2000-01-01 01:00:00 NaN\n",
"2000-01-01 02:00:00 NaN\n",
"2000-01-01 03:00:00 NaN\n",
"2000-01-01 04:00:00 NaN\n",
"... ...\n",
"2002-12-31 19:00:00 -\n",
"2002-12-31 20:00:00 -\n",
"2002-12-31 21:00:00 -\n",
"2002-12-31 22:00:00 -\n",
"2002-12-31 23:00:00 -\n",
"\n",
"[26304 rows x 1 columns]"
],
"text/html": [
"\n",
" <div id=\"df-3ad16fbc-1c92-4d98-874a-637988bb712a\" 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>2000-01-01 00:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01 01:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01 02:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01 03:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-01 04:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-12-31 19:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-12-31 20:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-12-31 21:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-12-31 22:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-12-31 23:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>26304 rows × 1 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-3ad16fbc-1c92-4d98-874a-637988bb712a')\"\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-3ad16fbc-1c92-4d98-874a-637988bb712a 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-3ad16fbc-1c92-4d98-874a-637988bb712a');\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-a5e05334-db6c-4670-a880-c074ef348237\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-a5e05334-db6c-4670-a880-c074ef348237')\"\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-a5e05334-db6c-4670-a880-c074ef348237 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": "data",
"summary": "{\n \"name\": \"data\",\n \"rows\": 26304,\n \"fields\": [\n {\n \"column\": \"Aurene\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 226,\n \"samples\": [\n 10,\n 24.5,\n 4.8\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 17
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "oYxhaVyua_Th",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "bab2174c-f042-467f-b1e1-98843fbd79cd"
},
"source": [
"data.info()"
],
"execution_count": 18,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"DatetimeIndex: 26304 entries, 2000-01-01 00:00:00 to 2002-12-31 23:00:00\n",
"Freq: 60T\n",
"Data columns (total 1 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Aurene 10918 non-null object\n",
"dtypes: object(1)\n",
"memory usage: 411.0+ KB\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ndmVdsMZck2W"
},
"source": [
"Catatan: data masih berupa `object`, dan belum diubah ke bentuk angka. Prapemrosesan ini serupa pada modul [hk73](https://nbviewer.jupyter.org/gist/taruma/b00880905f297013f046dad95dc2e284) (untuk membaca berkas bmkg)."
]
},
{
"cell_type": "code",
"metadata": {
"id": "SsWZrgyzMTsj",
"outputId": "17a7cbb6-60bb-4b2d-a57c-2a42164a97d6",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 677
}
},
"source": [
"data.sample(n=20) # menampilkan sampel 20 baris dalam data secara acak"
],
"execution_count": 19,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Aurene\n",
"2001-06-20 13:00:00 NaN\n",
"2001-10-19 03:00:00 2.5\n",
"2001-04-04 07:00:00 0.6\n",
"2001-10-05 07:00:00 NaN\n",
"2001-08-01 10:00:00 NaN\n",
"2002-09-14 07:00:00 -\n",
"2002-05-16 11:00:00 -\n",
"2000-02-15 18:00:00 NaN\n",
"2001-10-30 16:00:00 NaN\n",
"2002-02-09 19:00:00 -\n",
"2002-08-14 22:00:00 -\n",
"2002-07-25 21:00:00 -\n",
"2001-10-27 01:00:00 NaN\n",
"2001-06-20 05:00:00 NaN\n",
"2000-01-08 13:00:00 0.6\n",
"2002-03-08 16:00:00 -\n",
"2001-05-16 07:00:00 NaN\n",
"2001-09-27 02:00:00 NaN\n",
"2001-06-11 03:00:00 NaN\n",
"2000-03-19 06:00:00 2.6"
],
"text/html": [
"\n",
" <div id=\"df-48293b64-da43-45fc-99f7-e994e63c9642\" 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>2001-06-20 13:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-10-19 03:00:00</th>\n",
" <td>2.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-04-04 07:00:00</th>\n",
" <td>0.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-10-05 07:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-08-01 10:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-09-14 07:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-05-16 11:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-02-15 18:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-10-30 16:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-02-09 19:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-08-14 22:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-07-25 21:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-10-27 01:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-06-20 05:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-01-08 13:00:00</th>\n",
" <td>0.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-03-08 16:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-05-16 07:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-09-27 02:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-06-11 03:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000-03-19 06:00:00</th>\n",
" <td>2.6</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-48293b64-da43-45fc-99f7-e994e63c9642')\"\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-48293b64-da43-45fc-99f7-e994e63c9642 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-48293b64-da43-45fc-99f7-e994e63c9642');\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-27d4a568-7279-4491-9a77-3dcd874b85f2\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-27d4a568-7279-4491-9a77-3dcd874b85f2')\"\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-27d4a568-7279-4491-9a77-3dcd874b85f2 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\": \"data\",\n \"rows\": 20,\n \"fields\": [\n {\n \"column\": \"Aurene\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 4,\n \"samples\": [\n 0.6,\n 2.6,\n 2.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 19
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "3fHMWAqnhCwp",
"outputId": "f68babba-c4ad-4caf-a5c8-e893bb67dbf2",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
}
},
"source": [
"data.loc['2001'] # menampilkan data pada tahun tertentu"
],
"execution_count": 30,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Aurene\n",
"2001-01-01 00:00:00 NaN\n",
"2001-01-01 01:00:00 NaN\n",
"2001-01-01 02:00:00 NaN\n",
"2001-01-01 03:00:00 NaN\n",
"2001-01-01 04:00:00 NaN\n",
"... ...\n",
"2001-12-31 19:00:00 NaN\n",
"2001-12-31 20:00:00 NaN\n",
"2001-12-31 21:00:00 NaN\n",
"2001-12-31 22:00:00 NaN\n",
"2001-12-31 23:00:00 NaN\n",
"\n",
"[8760 rows x 1 columns]"
],
"text/html": [
"\n",
" <div id=\"df-5a1c2df4-67b9-47d7-9cc3-ea2ac2d6b560\" 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>2001-01-01 00:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01 01:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01 02:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01 03:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-01-01 04:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-12-31 19:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-12-31 20:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-12-31 21:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-12-31 22:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2001-12-31 23:00:00</th>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>8760 rows × 1 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-5a1c2df4-67b9-47d7-9cc3-ea2ac2d6b560')\"\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-5a1c2df4-67b9-47d7-9cc3-ea2ac2d6b560 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-5a1c2df4-67b9-47d7-9cc3-ea2ac2d6b560');\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-a2d86c5f-5cc6-48c9-bef5-465286a848df\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-a2d86c5f-5cc6-48c9-bef5-465286a848df')\"\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-a2d86c5f-5cc6-48c9-bef5-465286a848df 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\": \"data\",\n \"rows\": 8760,\n \"fields\": [\n {\n \"column\": \"Aurene\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": 0.0,\n \"max\": 70.0,\n \"num_unique_values\": 168,\n \"samples\": [\n 0.13,\n 1.6,\n 4.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 30
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "pHQIH6rRhFtp",
"outputId": "0f423940-61e1-4d37-82b4-7ba56262ccca",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 363
}
},
"source": [
"data['20020101 07:00': '20020101 16:00'] # menampilkan data diantara jam 7.00 sampai 16.00 pada tanggal 1 januari 2002"
],
"execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Aurene\n",
"2002-01-01 07:00:00 0.3\n",
"2002-01-01 08:00:00 -\n",
"2002-01-01 09:00:00 -\n",
"2002-01-01 10:00:00 -\n",
"2002-01-01 11:00:00 -\n",
"2002-01-01 12:00:00 -\n",
"2002-01-01 13:00:00 0.5\n",
"2002-01-01 14:00:00 -\n",
"2002-01-01 15:00:00 1.1\n",
"2002-01-01 16:00:00 -"
],
"text/html": [
"\n",
" <div id=\"df-9a70ae85-dc9f-4cf4-acf9-da36cb8b87c3\" 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 07:00:00</th>\n",
" <td>0.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 08:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 09:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 10:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 11:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 12:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 13:00:00</th>\n",
" <td>0.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 14:00:00</th>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 15:00:00</th>\n",
" <td>1.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-01-01 16:00:00</th>\n",
" <td>-</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-9a70ae85-dc9f-4cf4-acf9-da36cb8b87c3')\"\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-9a70ae85-dc9f-4cf4-acf9-da36cb8b87c3 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-9a70ae85-dc9f-4cf4-acf9-da36cb8b87c3');\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-478f2ea4-6185-4ed9-b878-3dbc1e78e33a\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-478f2ea4-6185-4ed9-b878-3dbc1e78e33a')\"\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-478f2ea4-6185-4ed9-b878-3dbc1e78e33a 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\": \"data['20020101 07:00': '20020101 16:00'] # menampilkan data diantara jam 7\",\n \"rows\": 10,\n \"fields\": [\n {\n \"column\": \"Aurene\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 4,\n \"samples\": [\n \" -\",\n 1.1,\n 0.3\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 21
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "IQyRDTQgdf5z"
},
"source": [
"# Changelog\n",
"\n",
"```\n",
"- 20240414 - 1.1.0 / 0.5.0 - Documentation\n",
"- 20191129 - 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/).\n"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment