Tutorial hidrokit.viz.table

  • Kategori: data visualization
  • Tujuan: Menampilkan dataset melalui bentuk tabel
  • Dokumentasi: readthedocs

Informasi notebook

  • notebook name: taruma_hidrokit_viz_table
  • notebook version/date: 1.0.1/20190713
  • notebook server: Google Colab
  • hidrokit version: 0.2.0
  • python version: 3.7

Instalasi hidrokit

In [0]:
### Instalasi melalui PyPI
!pip install hidrokit

### Instalasi melalui Github
# !pip install git+https://github.com/taruma/hidrokit.git

### Instalasi melalui Github (Latest)
# !pip install git+https://github.com/taruma/[email protected]
Collecting hidrokit
  Downloading https://files.pythonhosted.org/packages/43/9d/343d2a413a07463a21dd13369e31d664d6733bbfd46276abef5d804c83d1/hidrokit-0.2.0-py2.py3-none-any.whl
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from hidrokit) (3.0.3)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from hidrokit) (1.16.4)
Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from hidrokit) (0.24.2)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (2.5.3)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (1.1.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (2.4.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (0.10.0)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas->hidrokit) (2018.9)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib->hidrokit) (1.12.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib->hidrokit) (41.0.1)
Installing collected packages: hidrokit
Successfully installed hidrokit-0.2.0

Import Library

In [0]:
import numpy as np
import pandas as pd

Dataset

In [0]:
# Ambil dataset dari data test hidrokit
!wget -O dataset.csv "https://github.com/taruma/hidrokit/blob/master/tests/data/one_year_three_columns.csv?raw=true"
--2019-07-12 03:02:01--  https://github.com/taruma/hidrokit/blob/master/tests/data/one_year_three_columns.csv?raw=true
Resolving github.com (github.com)... 192.30.253.112
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/taruma/hidrokit/raw/master/tests/data/one_year_three_columns.csv [following]
--2019-07-12 03:02:01--  https://github.com/taruma/hidrokit/raw/master/tests/data/one_year_three_columns.csv
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/taruma/hidrokit/master/tests/data/one_year_three_columns.csv [following]
--2019-07-12 03:02:01--  https://raw.githubusercontent.com/taruma/hidrokit/master/tests/data/one_year_three_columns.csv
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7242 (7.1K) [text/plain]
Saving to: ‘dataset.csv’

dataset.csv         100%[===================>]   7.07K  --.-KB/s    in 0s      

2019-07-12 03:02:01 (90.8 MB/s) - ‘dataset.csv’ saved [7242/7242]

In [0]:
# Baca dataset
dataset = pd.read_csv('dataset.csv', index_col=0, parse_dates=True)
dataset.head(10)
Out[0]:
sta_a sta_b sta_c
2000-01-01 7 79 19
2000-01-02 17 79 65
2000-01-03 79 51 25
2000-01-04 48 75 31
2000-01-05 81 33 80
2000-01-06 26 3 96
2000-01-07 78 75 26
2000-01-08 71 95 65
2000-01-09 48 71 22
2000-01-10 32 89 88
In [0]:
# Info dataset
dataset.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 366 entries, 2000-01-01 to 2000-12-31
Data columns (total 3 columns):
sta_a    366 non-null int64
sta_b    366 non-null int64
sta_c    366 non-null int64
dtypes: int64(3)
memory usage: 11.4 KB

Fungsi table.pivot()

  • Tujuan: Menampilkan dataset dalam bentuk pivot/ringkasan
  • Sintaks: viz.table.pivot(dataframe, column=None, lang=None)
  • Return: DataFrame
  • Dokumentasi: readthedocs
In [0]:
from hidrokit.viz import table

Argument: None

Jika tidak ada kolom yang dipilih, maka akan dipilih kolom pertama (sta_a).

In [0]:
table.pivot(dataset)
Out[0]:
month 1 2 3 4 5 6 7 8 9 10 11 12
day
1 7.0 49.0 55.0 82.0 18.0 61.0 54.0 5.0 14.0 27.0 59.0 28.0
2 17.0 76.0 6.0 94.0 86.0 92.0 27.0 19.0 77.0 70.0 65.0 95.0
3 79.0 17.0 95.0 3.0 79.0 69.0 68.0 41.0 48.0 83.0 88.0 86.0
4 48.0 43.0 67.0 34.0 41.0 24.0 58.0 25.0 94.0 96.0 31.0 12.0
5 81.0 38.0 41.0 62.0 5.0 70.0 67.0 27.0 61.0 5.0 96.0 84.0
6 26.0 25.0 16.0 20.0 19.0 53.0 60.0 40.0 1.0 75.0 62.0 43.0
7 78.0 91.0 88.0 31.0 66.0 27.0 35.0 98.0 64.0 31.0 10.0 13.0
8 71.0 58.0 46.0 85.0 20.0 42.0 39.0 22.0 64.0 10.0 46.0 23.0
9 48.0 8.0 7.0 54.0 26.0 38.0 67.0 6.0 11.0 9.0 82.0 9.0
10 32.0 58.0 73.0 61.0 91.0 86.0 18.0 22.0 12.0 98.0 40.0 94.0
11 66.0 94.0 62.0 80.0 99.0 7.0 12.0 36.0 24.0 62.0 54.0 44.0
12 93.0 62.0 18.0 37.0 94.0 47.0 41.0 38.0 3.0 0.0 59.0 43.0
13 94.0 64.0 37.0 60.0 80.0 91.0 29.0 39.0 61.0 93.0 64.0 12.0
14 98.0 80.0 80.0 89.0 90.0 58.0 58.0 93.0 10.0 17.0 35.0 96.0
15 40.0 85.0 97.0 12.0 1.0 48.0 76.0 75.0 7.0 9.0 42.0 74.0
16 46.0 1.0 0.0 86.0 18.0 96.0 70.0 3.0 28.0 11.0 93.0 31.0
17 34.0 21.0 73.0 58.0 26.0 97.0 3.0 24.0 96.0 23.0 35.0 22.0
18 21.0 36.0 22.0 5.0 60.0 84.0 75.0 29.0 39.0 76.0 47.0 33.0
19 61.0 40.0 60.0 28.0 65.0 20.0 68.0 18.0 50.0 12.0 37.0 5.0
20 62.0 6.0 47.0 91.0 28.0 60.0 25.0 51.0 63.0 34.0 70.0 88.0
21 25.0 73.0 11.0 66.0 50.0 33.0 18.0 74.0 67.0 63.0 45.0 2.0
22 98.0 18.0 87.0 22.0 86.0 24.0 45.0 93.0 19.0 38.0 67.0 80.0
23 51.0 25.0 12.0 68.0 31.0 49.0 43.0 32.0 67.0 75.0 49.0 57.0
24 83.0 58.0 30.0 20.0 81.0 85.0 10.0 95.0 94.0 72.0 80.0 58.0
25 73.0 47.0 74.0 72.0 1.0 44.0 72.0 54.0 61.0 91.0 21.0 2.0
26 54.0 87.0 13.0 25.0 72.0 30.0 19.0 11.0 63.0 33.0 70.0 84.0
27 90.0 38.0 10.0 72.0 60.0 49.0 1.0 65.0 72.0 76.0 83.0 0.0
28 61.0 81.0 99.0 19.0 11.0 44.0 82.0 41.0 50.0 93.0 12.0 65.0
29 6.0 69.0 92.0 26.0 3.0 99.0 40.0 71.0 85.0 75.0 31.0 35.0
30 64.0 NaN 26.0 35.0 92.0 55.0 65.0 33.0 84.0 40.0 82.0 24.0
31 72.0 NaN 37.0 NaN 22.0 NaN 86.0 24.0 NaN 31.0 NaN 95.0

Argument: column=

Memilih kolom tertentu.

In [0]:
# Memilih stasiun b
table.pivot(dataset, column='sta_b')
Out[0]:
month 1 2 3 4 5 6 7 8 9 10 11 12
day
1 79.0 14.0 47.0 11.0 38.0 24.0 91.0 74.0 11.0 67.0 67.0 5.0
2 79.0 21.0 4.0 28.0 35.0 95.0 64.0 34.0 76.0 28.0 68.0 26.0
3 51.0 65.0 35.0 90.0 86.0 29.0 97.0 0.0 61.0 0.0 59.0 27.0
4 75.0 47.0 74.0 62.0 75.0 32.0 47.0 96.0 77.0 57.0 4.0 58.0
5 33.0 48.0 90.0 23.0 11.0 75.0 69.0 1.0 31.0 84.0 86.0 57.0
6 3.0 63.0 50.0 6.0 71.0 29.0 73.0 73.0 43.0 45.0 65.0 69.0
7 75.0 85.0 6.0 42.0 68.0 51.0 38.0 57.0 79.0 9.0 88.0 76.0
8 95.0 81.0 83.0 30.0 25.0 21.0 68.0 90.0 99.0 1.0 23.0 63.0
9 71.0 48.0 28.0 13.0 44.0 76.0 51.0 58.0 95.0 18.0 31.0 50.0
10 89.0 23.0 32.0 47.0 61.0 66.0 37.0 34.0 10.0 67.0 1.0 94.0
11 63.0 90.0 28.0 73.0 58.0 47.0 3.0 93.0 38.0 32.0 79.0 90.0
12 41.0 58.0 13.0 58.0 66.0 3.0 54.0 8.0 45.0 46.0 75.0 12.0
13 0.0 3.0 29.0 44.0 99.0 67.0 34.0 84.0 88.0 8.0 50.0 60.0
14 15.0 31.0 5.0 95.0 24.0 83.0 86.0 78.0 99.0 34.0 83.0 75.0
15 73.0 44.0 4.0 22.0 45.0 51.0 3.0 27.0 34.0 41.0 22.0 53.0
16 22.0 39.0 23.0 51.0 74.0 75.0 83.0 63.0 56.0 62.0 14.0 54.0
17 33.0 70.0 52.0 16.0 52.0 71.0 16.0 71.0 91.0 20.0 35.0 17.0
18 38.0 90.0 93.0 16.0 87.0 95.0 72.0 85.0 80.0 1.0 68.0 56.0
19 50.0 69.0 73.0 13.0 95.0 44.0 46.0 77.0 75.0 42.0 52.0 67.0
20 45.0 66.0 3.0 93.0 67.0 67.0 17.0 47.0 34.0 46.0 42.0 17.0
21 40.0 73.0 77.0 28.0 57.0 78.0 27.0 65.0 50.0 99.0 56.0 0.0
22 76.0 29.0 50.0 32.0 8.0 64.0 63.0 67.0 73.0 21.0 77.0 32.0
23 7.0 9.0 15.0 41.0 69.0 51.0 41.0 96.0 0.0 1.0 81.0 80.0
24 12.0 72.0 17.0 39.0 64.0 60.0 99.0 14.0 10.0 23.0 2.0 88.0
25 55.0 97.0 25.0 70.0 42.0 64.0 65.0 25.0 62.0 89.0 3.0 93.0
26 40.0 22.0 72.0 88.0 32.0 68.0 81.0 59.0 86.0 30.0 57.0 76.0
27 40.0 71.0 45.0 14.0 65.0 82.0 7.0 1.0 11.0 49.0 16.0 62.0
28 32.0 98.0 75.0 44.0 61.0 13.0 95.0 44.0 74.0 5.0 47.0 17.0
29 75.0 79.0 5.0 19.0 72.0 5.0 34.0 13.0 1.0 6.0 7.0 96.0
30 51.0 NaN 67.0 74.0 54.0 58.0 42.0 75.0 58.0 13.0 84.0 17.0
31 75.0 NaN 50.0 NaN 77.0 NaN 1.0 14.0 NaN 25.0 NaN 31.0

Argument: lang=

Memberi nama bulan pada kolom. Ada dua pilihan yaitu kode bahasa indonesia id dan bahasa inggris en.

In [0]:
# Menampilkan data stasiun c dengan nama bulan 
table.pivot(dataset, column='sta_c', lang='en')
Out[0]:
month Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
day
1 19.0 8.0 8.0 75.0 56.0 34.0 66.0 18.0 41.0 41.0 83.0 10.0
2 65.0 36.0 42.0 96.0 28.0 40.0 54.0 53.0 75.0 31.0 46.0 59.0
3 25.0 10.0 57.0 67.0 22.0 41.0 76.0 59.0 89.0 44.0 16.0 75.0
4 31.0 54.0 81.0 0.0 42.0 69.0 5.0 27.0 21.0 4.0 61.0 17.0
5 80.0 60.0 51.0 96.0 84.0 77.0 74.0 35.0 43.0 46.0 26.0 55.0
6 96.0 21.0 57.0 97.0 23.0 98.0 29.0 23.0 77.0 52.0 15.0 42.0
7 26.0 57.0 49.0 46.0 65.0 35.0 31.0 43.0 22.0 18.0 16.0 4.0
8 65.0 93.0 98.0 11.0 74.0 89.0 71.0 68.0 76.0 32.0 13.0 20.0
9 22.0 96.0 22.0 15.0 95.0 83.0 16.0 83.0 54.0 61.0 68.0 65.0
10 88.0 68.0 60.0 75.0 45.0 31.0 17.0 1.0 68.0 86.0 26.0 48.0
11 55.0 52.0 87.0 65.0 67.0 90.0 20.0 93.0 72.0 54.0 36.0 84.0
12 80.0 44.0 77.0 98.0 82.0 36.0 59.0 66.0 72.0 55.0 23.0 38.0
13 68.0 36.0 67.0 61.0 89.0 22.0 39.0 42.0 10.0 86.0 11.0 39.0
14 90.0 79.0 30.0 86.0 29.0 61.0 43.0 58.0 63.0 0.0 72.0 97.0
15 73.0 10.0 1.0 79.0 86.0 92.0 25.0 35.0 97.0 47.0 26.0 40.0
16 12.0 47.0 0.0 92.0 94.0 3.0 89.0 81.0 58.0 67.0 65.0 57.0
17 72.0 63.0 31.0 85.0 65.0 43.0 86.0 72.0 38.0 44.0 73.0 30.0
18 37.0 13.0 40.0 67.0 29.0 67.0 2.0 24.0 50.0 53.0 84.0 9.0
19 45.0 20.0 52.0 31.0 89.0 41.0 29.0 28.0 47.0 16.0 49.0 82.0
20 92.0 2.0 51.0 33.0 63.0 20.0 89.0 36.0 75.0 29.0 50.0 41.0
21 4.0 49.0 26.0 98.0 41.0 65.0 77.0 19.0 15.0 49.0 22.0 52.0
22 12.0 49.0 33.0 60.0 8.0 59.0 17.0 36.0 41.0 19.0 93.0 81.0
23 45.0 35.0 38.0 54.0 19.0 37.0 1.0 33.0 39.0 74.0 41.0 0.0
24 92.0 70.0 55.0 53.0 46.0 90.0 50.0 15.0 56.0 95.0 47.0 66.0
25 27.0 35.0 14.0 88.0 62.0 33.0 74.0 2.0 44.0 54.0 87.0 4.0
26 45.0 21.0 10.0 50.0 22.0 96.0 55.0 94.0 44.0 49.0 64.0 48.0
27 13.0 42.0 62.0 77.0 52.0 43.0 97.0 85.0 88.0 80.0 25.0 70.0
28 84.0 34.0 19.0 72.0 35.0 77.0 88.0 89.0 16.0 46.0 82.0 56.0
29 8.0 96.0 73.0 25.0 27.0 41.0 83.0 32.0 51.0 30.0 1.0 4.0
30 45.0 NaN 97.0 92.0 39.0 0.0 69.0 80.0 18.0 26.0 44.0 55.0
31 76.0 NaN 7.0 NaN 69.0 NaN 65.0 26.0 NaN 77.0 NaN 39.0

Changelog

- 20190713 - 1.0.1 - Update information
- 20190712 - 1.0.0 - Initial

Source code in this notebook is licensed under a MIT License. Data in this notebook is licensed under a Creative Common Attribution 4.0 International.