Last active
July 17, 2019 13:34
-
-
Save taruma/2a33a8877ebc79ad16e0aed21c35e0ca to your computer and use it in GitHub Desktop.
taruma_hk60_resample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "taruma_hk60_resample", | |
"version": "0.3.2", | |
"provenance": [], | |
"collapsed_sections": [], | |
"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/2a33a8877ebc79ad16e0aed21c35e0ca/taruma_hk60_resample.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "f7sSLaY7hEV5", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Berdasarkan isu [#60](https://github.com/taruma/hidrokit/issues/60): __Menentukan kriteria berdasarkan total nilai bulanan__\n", | |
"\n", | |
"Deskripsi permasalahan:\n", | |
"- Saya memiliki __dataset harian__ nilai a, b, c selama 50 tahun.\n", | |
"- Saya ingin mengkategorikan nilai di kolom a, __berdasarkan__ nilai total bulanan-nya.\n", | |
"- Hasil pengategorian tersebut dibuat pada kolom baru bernama 'kategori'." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "cn82ATqtg5FL", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# import library\n", | |
"import pandas as pd\n", | |
"import numpy as np" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "MoRqkKdnhUFd", | |
"colab_type": "code", | |
"outputId": "1d3cf757-b39c-47fe-826f-4d323058b595", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 170 | |
} | |
}, | |
"source": [ | |
"# buat dataset random\n", | |
"SEED = 110891\n", | |
"np.random.seed(SEED)\n", | |
"date_index = pd.date_range('20000101', '20501231')\n", | |
"dataset = pd.DataFrame(\n", | |
" index=date_index,\n", | |
" data=np.random.rand(len(date_index), 3)*10,\n", | |
" columns='a b c'.split()\n", | |
")\n", | |
"dataset.info()" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"<class 'pandas.core.frame.DataFrame'>\n", | |
"DatetimeIndex: 18628 entries, 2000-01-01 to 2050-12-31\n", | |
"Freq: D\n", | |
"Data columns (total 3 columns):\n", | |
"a 18628 non-null float64\n", | |
"b 18628 non-null float64\n", | |
"c 18628 non-null float64\n", | |
"dtypes: float64(3)\n", | |
"memory usage: 582.1 KB\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "WqdHuxfphyI8", | |
"colab_type": "code", | |
"outputId": "fe12e39a-364d-4429-ee32-169dea51fb64", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 204 | |
} | |
}, | |
"source": [ | |
"dataset.head()" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>a</th>\n", | |
" <th>b</th>\n", | |
" <th>c</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>2000-01-01</th>\n", | |
" <td>2.877766</td>\n", | |
" <td>3.213378</td>\n", | |
" <td>2.609509</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-02</th>\n", | |
" <td>6.087079</td>\n", | |
" <td>0.528814</td>\n", | |
" <td>2.181410</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-03</th>\n", | |
" <td>7.788553</td>\n", | |
" <td>8.597564</td>\n", | |
" <td>3.401175</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-04</th>\n", | |
" <td>7.952444</td>\n", | |
" <td>3.182324</td>\n", | |
" <td>1.600600</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-05</th>\n", | |
" <td>1.721316</td>\n", | |
" <td>7.618591</td>\n", | |
" <td>5.018759</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" a b c\n", | |
"2000-01-01 2.877766 3.213378 2.609509\n", | |
"2000-01-02 6.087079 0.528814 2.181410\n", | |
"2000-01-03 7.788553 8.597564 3.401175\n", | |
"2000-01-04 7.952444 3.182324 1.600600\n", | |
"2000-01-05 1.721316 7.618591 5.018759" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 3 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "WQJzzyVsqiC9", | |
"colab_type": "code", | |
"outputId": "c9d6ca08-6fda-4e38-b47e-11acbb869dea", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 1000 | |
} | |
}, | |
"source": [ | |
"# menghitung total ch setiap bulannya\n", | |
"total_summary = dataset.groupby([dataset.index.year, dataset.index.month]).sum()\n", | |
"total_summary" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th>a</th>\n", | |
" <th>b</th>\n", | |
" <th>c</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th rowspan=\"12\" valign=\"top\">2000</th>\n", | |
" <th>1</th>\n", | |
" <td>162.847727</td>\n", | |
" <td>156.897045</td>\n", | |
" <td>144.812644</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>146.883002</td>\n", | |
" <td>163.938908</td>\n", | |
" <td>125.541164</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>149.917733</td>\n", | |
" <td>162.343038</td>\n", | |
" <td>153.770483</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>151.332312</td>\n", | |
" <td>146.398578</td>\n", | |
" <td>131.572011</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>148.824870</td>\n", | |
" <td>159.312776</td>\n", | |
" <td>178.204217</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>142.645200</td>\n", | |
" <td>141.804644</td>\n", | |
" <td>162.177388</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>170.140213</td>\n", | |
" <td>130.409430</td>\n", | |
" <td>191.273702</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>170.068540</td>\n", | |
" <td>159.861622</td>\n", | |
" <td>179.001989</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>178.699585</td>\n", | |
" <td>157.825042</td>\n", | |
" <td>144.558428</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>145.530305</td>\n", | |
" <td>191.522354</td>\n", | |
" <td>178.904414</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>128.861376</td>\n", | |
" <td>152.381631</td>\n", | |
" <td>121.446012</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>128.531776</td>\n", | |
" <td>145.206447</td>\n", | |
" <td>160.007800</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"12\" valign=\"top\">2001</th>\n", | |
" <th>1</th>\n", | |
" <td>165.739167</td>\n", | |
" <td>150.058786</td>\n", | |
" <td>160.826603</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>141.511927</td>\n", | |
" <td>134.187962</td>\n", | |
" <td>130.801650</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>135.688425</td>\n", | |
" <td>177.826575</td>\n", | |
" <td>173.841181</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>167.878367</td>\n", | |
" <td>163.536799</td>\n", | |
" <td>167.083027</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>159.875967</td>\n", | |
" <td>168.663616</td>\n", | |
" <td>120.514476</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>155.665123</td>\n", | |
" <td>153.639577</td>\n", | |
" <td>153.308357</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>142.746376</td>\n", | |
" <td>139.065767</td>\n", | |
" <td>147.011501</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>142.728787</td>\n", | |
" <td>174.440000</td>\n", | |
" <td>148.623053</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>116.060098</td>\n", | |
" <td>165.032239</td>\n", | |
" <td>153.688107</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>168.868071</td>\n", | |
" <td>164.222337</td>\n", | |
" <td>170.667792</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>140.969798</td>\n", | |
" <td>155.106032</td>\n", | |
" <td>121.242189</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>123.714519</td>\n", | |
" <td>163.179190</td>\n", | |
" <td>166.616499</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"6\" valign=\"top\">2002</th>\n", | |
" <th>1</th>\n", | |
" <td>167.053233</td>\n", | |
" <td>155.069400</td>\n", | |
" <td>171.605847</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>120.012374</td>\n", | |
" <td>146.039734</td>\n", | |
" <td>153.264692</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>183.218227</td>\n", | |
" <td>164.571052</td>\n", | |
" <td>154.357133</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>154.822616</td>\n", | |
" <td>120.226232</td>\n", | |
" <td>102.963488</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>169.889488</td>\n", | |
" <td>152.184870</td>\n", | |
" <td>142.519123</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>151.163008</td>\n", | |
" <td>130.519755</td>\n", | |
" <td>151.762828</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"6\" valign=\"top\">2048</th>\n", | |
" <th>7</th>\n", | |
" <td>148.672508</td>\n", | |
" <td>167.142954</td>\n", | |
" <td>164.381128</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>126.655985</td>\n", | |
" <td>148.710034</td>\n", | |
" <td>144.413049</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>183.513775</td>\n", | |
" <td>114.640279</td>\n", | |
" <td>169.897208</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>135.829907</td>\n", | |
" <td>151.918643</td>\n", | |
" <td>176.459592</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>146.398529</td>\n", | |
" <td>125.322861</td>\n", | |
" <td>148.996056</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>159.041660</td>\n", | |
" <td>156.619241</td>\n", | |
" <td>165.230088</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"12\" valign=\"top\">2049</th>\n", | |
" <th>1</th>\n", | |
" <td>157.052500</td>\n", | |
" <td>139.911295</td>\n", | |
" <td>145.751750</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>117.204951</td>\n", | |
" <td>135.909696</td>\n", | |
" <td>128.467320</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>140.775834</td>\n", | |
" <td>172.049295</td>\n", | |
" <td>186.388653</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>142.940225</td>\n", | |
" <td>156.801915</td>\n", | |
" <td>141.438030</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>175.040427</td>\n", | |
" <td>157.488158</td>\n", | |
" <td>156.365536</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>140.708484</td>\n", | |
" <td>133.383572</td>\n", | |
" <td>147.509383</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>145.790755</td>\n", | |
" <td>165.487569</td>\n", | |
" <td>154.127876</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>149.804165</td>\n", | |
" <td>169.480737</td>\n", | |
" <td>138.583017</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>158.301834</td>\n", | |
" <td>164.360739</td>\n", | |
" <td>164.492783</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>159.818715</td>\n", | |
" <td>141.081036</td>\n", | |
" <td>142.240236</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>96.027429</td>\n", | |
" <td>154.389690</td>\n", | |
" <td>154.491933</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>168.802017</td>\n", | |
" <td>140.951503</td>\n", | |
" <td>148.711046</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"12\" valign=\"top\">2050</th>\n", | |
" <th>1</th>\n", | |
" <td>175.387880</td>\n", | |
" <td>156.662521</td>\n", | |
" <td>203.628996</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>137.018246</td>\n", | |
" <td>133.811524</td>\n", | |
" <td>144.568716</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>161.716170</td>\n", | |
" <td>143.697188</td>\n", | |
" <td>143.519191</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>162.027600</td>\n", | |
" <td>135.305125</td>\n", | |
" <td>156.008888</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>154.067237</td>\n", | |
" <td>161.674996</td>\n", | |
" <td>169.782035</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>153.781478</td>\n", | |
" <td>158.463390</td>\n", | |
" <td>171.016871</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>149.692955</td>\n", | |
" <td>171.071892</td>\n", | |
" <td>144.742615</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>163.018816</td>\n", | |
" <td>161.417455</td>\n", | |
" <td>157.176567</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>142.620717</td>\n", | |
" <td>171.070855</td>\n", | |
" <td>117.322726</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>138.459144</td>\n", | |
" <td>137.613439</td>\n", | |
" <td>164.343386</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>150.625937</td>\n", | |
" <td>147.692128</td>\n", | |
" <td>164.288570</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>157.485470</td>\n", | |
" <td>184.238850</td>\n", | |
" <td>160.089807</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>612 rows × 3 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" a b c\n", | |
"2000 1 162.847727 156.897045 144.812644\n", | |
" 2 146.883002 163.938908 125.541164\n", | |
" 3 149.917733 162.343038 153.770483\n", | |
" 4 151.332312 146.398578 131.572011\n", | |
" 5 148.824870 159.312776 178.204217\n", | |
" 6 142.645200 141.804644 162.177388\n", | |
" 7 170.140213 130.409430 191.273702\n", | |
" 8 170.068540 159.861622 179.001989\n", | |
" 9 178.699585 157.825042 144.558428\n", | |
" 10 145.530305 191.522354 178.904414\n", | |
" 11 128.861376 152.381631 121.446012\n", | |
" 12 128.531776 145.206447 160.007800\n", | |
"2001 1 165.739167 150.058786 160.826603\n", | |
" 2 141.511927 134.187962 130.801650\n", | |
" 3 135.688425 177.826575 173.841181\n", | |
" 4 167.878367 163.536799 167.083027\n", | |
" 5 159.875967 168.663616 120.514476\n", | |
" 6 155.665123 153.639577 153.308357\n", | |
" 7 142.746376 139.065767 147.011501\n", | |
" 8 142.728787 174.440000 148.623053\n", | |
" 9 116.060098 165.032239 153.688107\n", | |
" 10 168.868071 164.222337 170.667792\n", | |
" 11 140.969798 155.106032 121.242189\n", | |
" 12 123.714519 163.179190 166.616499\n", | |
"2002 1 167.053233 155.069400 171.605847\n", | |
" 2 120.012374 146.039734 153.264692\n", | |
" 3 183.218227 164.571052 154.357133\n", | |
" 4 154.822616 120.226232 102.963488\n", | |
" 5 169.889488 152.184870 142.519123\n", | |
" 6 151.163008 130.519755 151.762828\n", | |
"... ... ... ...\n", | |
"2048 7 148.672508 167.142954 164.381128\n", | |
" 8 126.655985 148.710034 144.413049\n", | |
" 9 183.513775 114.640279 169.897208\n", | |
" 10 135.829907 151.918643 176.459592\n", | |
" 11 146.398529 125.322861 148.996056\n", | |
" 12 159.041660 156.619241 165.230088\n", | |
"2049 1 157.052500 139.911295 145.751750\n", | |
" 2 117.204951 135.909696 128.467320\n", | |
" 3 140.775834 172.049295 186.388653\n", | |
" 4 142.940225 156.801915 141.438030\n", | |
" 5 175.040427 157.488158 156.365536\n", | |
" 6 140.708484 133.383572 147.509383\n", | |
" 7 145.790755 165.487569 154.127876\n", | |
" 8 149.804165 169.480737 138.583017\n", | |
" 9 158.301834 164.360739 164.492783\n", | |
" 10 159.818715 141.081036 142.240236\n", | |
" 11 96.027429 154.389690 154.491933\n", | |
" 12 168.802017 140.951503 148.711046\n", | |
"2050 1 175.387880 156.662521 203.628996\n", | |
" 2 137.018246 133.811524 144.568716\n", | |
" 3 161.716170 143.697188 143.519191\n", | |
" 4 162.027600 135.305125 156.008888\n", | |
" 5 154.067237 161.674996 169.782035\n", | |
" 6 153.781478 158.463390 171.016871\n", | |
" 7 149.692955 171.071892 144.742615\n", | |
" 8 163.018816 161.417455 157.176567\n", | |
" 9 142.620717 171.070855 117.322726\n", | |
" 10 138.459144 137.613439 164.343386\n", | |
" 11 150.625937 147.692128 164.288570\n", | |
" 12 157.485470 184.238850 160.089807\n", | |
"\n", | |
"[612 rows x 3 columns]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 4 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "J54gY_fKjDGg", | |
"colab_type": "code", | |
"outputId": "797a17fc-cb3e-46b0-c669-8c33918a7d8b", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"# Memilih nilai spesifik bulan dan tahun pada kolom tertentu\n", | |
"TAHUN, BULAN, KOLOM = 2000, 1, 'a'\n", | |
"total_summary.loc[(TAHUN, BULAN), KOLOM]" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"162.84772662835172" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LmiD9JurjS5L", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# \n", | |
"\n", | |
"def total_each_month(x, column='ch', summary=None):\n", | |
" year = x['index'].year\n", | |
" month = x['index'].month\n", | |
" return summary.loc[(year, month), column]\n", | |
"\n", | |
"def criteria(value):\n", | |
" if value < 130:\n", | |
" return \"rendah\"\n", | |
" elif value >= 130 and value <= 160:\n", | |
" return \"sedang\"\n", | |
" else:\n", | |
" return \"tinggi\"\n", | |
"\n", | |
"KOLOM = 'a'\n", | |
" \n", | |
"dataset['total_a'] = dataset.reset_index().apply(lambda x: total_each_month(x, column=KOLOM, summary=total_summary), axis=1).values\n", | |
"dataset['kategori'] = dataset['total_a'].apply(criteria)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "v7iE2vvC2TSu", | |
"colab_type": "code", | |
"outputId": "e9c09b23-974f-4875-9e86-e6a8ced3961f", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 204 | |
} | |
}, | |
"source": [ | |
"dataset.head()" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>a</th>\n", | |
" <th>b</th>\n", | |
" <th>c</th>\n", | |
" <th>total_a</th>\n", | |
" <th>kategori</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>2000-01-01</th>\n", | |
" <td>2.877766</td>\n", | |
" <td>3.213378</td>\n", | |
" <td>2.609509</td>\n", | |
" <td>162.847727</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-02</th>\n", | |
" <td>6.087079</td>\n", | |
" <td>0.528814</td>\n", | |
" <td>2.181410</td>\n", | |
" <td>162.847727</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-03</th>\n", | |
" <td>7.788553</td>\n", | |
" <td>8.597564</td>\n", | |
" <td>3.401175</td>\n", | |
" <td>162.847727</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-04</th>\n", | |
" <td>7.952444</td>\n", | |
" <td>3.182324</td>\n", | |
" <td>1.600600</td>\n", | |
" <td>162.847727</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2000-01-05</th>\n", | |
" <td>1.721316</td>\n", | |
" <td>7.618591</td>\n", | |
" <td>5.018759</td>\n", | |
" <td>162.847727</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" a b c total_a kategori\n", | |
"2000-01-01 2.877766 3.213378 2.609509 162.847727 tinggi\n", | |
"2000-01-02 6.087079 0.528814 2.181410 162.847727 tinggi\n", | |
"2000-01-03 7.788553 8.597564 3.401175 162.847727 tinggi\n", | |
"2000-01-04 7.952444 3.182324 1.600600 162.847727 tinggi\n", | |
"2000-01-05 1.721316 7.618591 5.018759 162.847727 tinggi" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ZrisfWzl2LSn", | |
"colab_type": "code", | |
"outputId": "49283388-6ed6-4e63-9324-ab18107a5e0b", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 359 | |
} | |
}, | |
"source": [ | |
"dataset.sample(n=10, random_state=SEED)" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<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>a</th>\n", | |
" <th>b</th>\n", | |
" <th>c</th>\n", | |
" <th>total_a</th>\n", | |
" <th>kategori</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>2048-11-11</th>\n", | |
" <td>1.223814</td>\n", | |
" <td>0.436503</td>\n", | |
" <td>5.906254</td>\n", | |
" <td>146.398529</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2006-04-05</th>\n", | |
" <td>7.494172</td>\n", | |
" <td>3.334511</td>\n", | |
" <td>1.982660</td>\n", | |
" <td>161.010925</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2038-06-19</th>\n", | |
" <td>1.737448</td>\n", | |
" <td>1.266665</td>\n", | |
" <td>2.950612</td>\n", | |
" <td>130.366532</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2022-06-14</th>\n", | |
" <td>7.999164</td>\n", | |
" <td>1.079437</td>\n", | |
" <td>4.436997</td>\n", | |
" <td>171.157052</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2012-10-24</th>\n", | |
" <td>9.006064</td>\n", | |
" <td>1.942224</td>\n", | |
" <td>0.583746</td>\n", | |
" <td>160.424030</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2007-06-10</th>\n", | |
" <td>0.790671</td>\n", | |
" <td>6.943135</td>\n", | |
" <td>1.963164</td>\n", | |
" <td>139.102825</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2008-03-31</th>\n", | |
" <td>7.362242</td>\n", | |
" <td>3.070636</td>\n", | |
" <td>9.000031</td>\n", | |
" <td>143.855427</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2004-08-20</th>\n", | |
" <td>6.696845</td>\n", | |
" <td>2.676529</td>\n", | |
" <td>3.607975</td>\n", | |
" <td>179.573750</td>\n", | |
" <td>tinggi</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2014-12-28</th>\n", | |
" <td>1.035354</td>\n", | |
" <td>8.811785</td>\n", | |
" <td>0.589958</td>\n", | |
" <td>143.172699</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2044-07-11</th>\n", | |
" <td>3.686524</td>\n", | |
" <td>8.440504</td>\n", | |
" <td>0.009692</td>\n", | |
" <td>151.676157</td>\n", | |
" <td>sedang</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" a b c total_a kategori\n", | |
"2048-11-11 1.223814 0.436503 5.906254 146.398529 sedang\n", | |
"2006-04-05 7.494172 3.334511 1.982660 161.010925 tinggi\n", | |
"2038-06-19 1.737448 1.266665 2.950612 130.366532 sedang\n", | |
"2022-06-14 7.999164 1.079437 4.436997 171.157052 tinggi\n", | |
"2012-10-24 9.006064 1.942224 0.583746 160.424030 tinggi\n", | |
"2007-06-10 0.790671 6.943135 1.963164 139.102825 sedang\n", | |
"2008-03-31 7.362242 3.070636 9.000031 143.855427 sedang\n", | |
"2004-08-20 6.696845 2.676529 3.607975 179.573750 tinggi\n", | |
"2014-12-28 1.035354 8.811785 0.589958 143.172699 sedang\n", | |
"2044-07-11 3.686524 8.440504 0.009692 151.676157 sedang" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 8 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "l277kxD6I_y3", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Changelog\n", | |
"\n", | |
"```\n", | |
"- 20190717 - 1.0.0 - Initial\n", | |
"```\n", | |
"\n", | |
"#### Copyright © 2019 [Taruma Sakti Megariansyah](https://taruma.github.io)\n", | |
"\n", | |
"Source code in this notebook is licensed under a [MIT License](https://choosealicense.com/licenses/mit/). Data in this notebook is licensed under a [Creative Common Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). " | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment