SlideShare a Scribd company logo
1 of 22
A Hacking Toolset for
Big Tabular Files
2021年2月18日(木) 下野寿之 — Toshiyuki Shimono
JAPAN.PM 2021
1
内容 (大体の流れ) :
1. Perl やっぱり使い易い!!
2. テーブルデータ用のツール作った
3. 便利!
4. 結局 何したかった?
2
Perl
II
Practical
Extraction
and
Report
Language
成熟した機能
 文字列処理が器用
 括弧をよく省略できる
(非教科書的ではある)
 浮動小数点演算も
十進数計算も切替が簡単
 CPAN — 安心感が高い
 数十年後も多分使える
→ use 5.018 ; と書くだけ
テキスト生データをどこでも手際よく
安心して使いたいという観点から.
3
私が何を作ったか?
なぜ作ったか?
どんな利点があるのか?
https://www.slidesha
re.net/shimonotoshiy
uki/sqlgen190412
私のデータ分析に
対する問題意識:
↑ これはPerlとは
あまり関係無い
4
データ元: 「都道府県別新型コロナウイルス感染者数マップ(ジャッグジャパン株式会社提供)」
5
(タブ区切り)テキストデータを
容易に扱うCLIを作った。
0. CLI = Command Line Interface (要は黒い画面)
1. CSVデータでもTSVデータでも、分析の為の
テーブルの意味理解の作業は意外と大変 !!
2. 前処理などの前のデータ読解ツールを作った。
なぜ作ったか?
 シェル芸でも大変だったから。
 Excel, R, SQL, Pandas も物足りない。
データ分析の迅速性大事。でも今まで無理だった!
6
CLI: Unixコマンドとして(も)使える
7
NAME FUNCTION DETAIL
xcol Table looking-up Similar to SQL-join, Unix-join, Excel-vlookup
sampler Probabilistic extraction Can specify random seeds, probability weight.
keyvalues Key multiplicity Inspects many aspects of a file of “key + value”.
kvcmp Check the KV relation When 2 KV files are given, check the sameness.
colgrep Column-wise grep More useful than Unix-grep
idmaker ID creation Second DB normalization
denomfind Finding common denom.Guessing the whole number from the fractions.
shuffler Shuffle lines Also an option with preserving the heading line.
alluniq Check the uniqueness Also print out how many same lines.
expskip Logarithmic extraction Useful for taking a glace at the first stage.
eofcheck Check the end of file Important at the initial stage of data analysis task.
dirhier Directory structure How many files on each depth.
timeput Time stamp on each line When one line comes, time added on its head.
「無いと不便」と思った機能を次々実装。
☝︎2016-08-18 ↓2018-06-24
https://www.ite.or.jp/wp/wp-content/uploads/opendata/tool201807.pdf
8
この文書に、コンセプトや一部のコマンドの使い方を解説。
この頃までにコンセプトは固まったが、非正常系の動作はさらに考え変更中。
どんな利点があるか?
—かゆい所に手が届く. テキストデータに対して.
9
AWKやcutコマンドより便利な
列選択コマンドを作ってみた。
csel コマンドの使い方の例:
csel –t 2 ; # 入力2列目を末尾列に移動して出力。
csel –h -1 ; # 入力の末尾列を出力の先頭列に移動。
csel –p 5,7..10 ; # 5列と7,8,9,10列目だけを出力。
csel –d 6..9 ; # 入力の6,7,8,9列目を出力しない。
AWKや Unixのcutコマンドで書くより、簡単。
https://metacpan.org/pod/distribution/Table-Hack/scripts/csel
https://github.com/tulamili/bin4tsv/blob/master/cols
10
colorplus : 文字/数字に色を付ける
wc * | coloplus -3
colorplus (Perlで書かれたプログラム) に標準入力からテキストを渡すと、
-3 のオプションで数字の部分だけ、下から3桁区切りに色を付ける。
数が読みやすくなる。
「 -3 」以外にも多数の有用なオプション(コマンドスイッチ)を用意。-4など。
https://metacpan.org/release/App-colorplus
https://github.com/tulamili/bin4tsv/blob/master/colorplus 11
colorplus で、5列ごとに背景を着色
colorplus で様々な着色を可能とした。
-t 5 により、列を5列ごとに背景を着色。
他には、 -s で指定した正規表現に着色、-0 で着色の除去など。
詳細未知のデータを与えられて、最初に眺め、意味を把握するときに有用。12
colorplus –t 5 foo | less –N -S
crosstable : クロス表(2元分割表)
> crosstable foo
2列の表形式データを受け取ると、それをクロス表で出力(タブ文字区切り)。
csv形式も可能。色は除去可能。1行目が変数名の並びでも、対応可能。
他にもいろいろな小機能あり(オプションで指定可能)。
https://metacpan.org/release/CLI-Contingency-Table 13
少しシェル芸的に
2列を取り出して、
クロス集計 ( crosstable )をして、
文字の「0」だけ青色に着色( colorplus –s 0 –b blue)した。
14
freq : 頻度表を出力
( sort | uniq –c の様な動作を高速化/高機能化)
各行の文字列を1件ずつの値と見なし、異なる値が何件出現したかを出力する。
— 出力の、タブ文字で区切って、左に数で件数、右に値。
いろいろな便利機能 :
• 15秒ごとに、何行既に読んだかなど、標準エラー出力に情報を出す。
• 最後に標準エラー出力に、何件処理したか、などの便利情報を出す。
https://metacpan.org/pod/distribution/Table-Hack/scripts/freq
15
freq : with options
For freq,
-f for sorting in frequency number,
-r for reversing the order,
-% for showing the ratio among the whole,
-s for cumulative counting,
-= for recognizing the heading line (appeared in the previous page.)
16
実務的な例
( ツイッター とか コロナ とか )
17
ツイッターの発言のデータの
日付と時間帯で, 個数を集計
日付/時間 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
2013-12-10 32 157 153 156 139 161 170 182 315 356 276 221 256
2013-12-11 127 93 64 58 39 72 90 144 200 149 170 116 177 144 170 149 156 268 318 253 216 187 203 235
2013-12-12 136 86 68 63 46 61 64 115 177 134 130 121 463 582 423 442 703 1285 1394 1446 1444 1611 2023 1974
2013-12-13 1532 958 634 478 396 403 526 837 1122 1097 1457 1386 1988 1816 2037 3025 3662 4125 4551 5062 4655 4993 5576 2969
2013-12-14 2873 1626 1139 1018 529 682 807 1164 1655 2115 2536 2715 2868 3454 3720 3812 3611 3438 4202 5005 2557 3133 5031 4274
2013-12-15 3617 2232 1694 1330 1051 974 1173 1732 2590 3549 4942 5871 5306 3056 3571 5247 6666 6798 6964 2597 1710 3382 7879 6425
2013-12-16 4623 2741 1631 1304 927 1094 1185 2053 2597 2474 3415 3614 4580 4836 4187 4999 4115 4122 5957 6427 6328 6793 6545 5963
2013-12-17 4045 2405 1545 1189 1007 946 1237 2692 3532 3435 4178 4925 6158 5049 4756 4375 3890 4138 5090 6265 7628 7077 6639 6325
2013-12-18 4458 2807 1713 1404 1131 1051 1347 1954 2299 2624 3412 2707 1962 1773 1910 3851 5263 6359 7177 6583 6936 6644 6234 6119
2013-12-19 4637 3064 1739 1509 1141 1100 1394 2362 2994 3897 3999 4344 5260 6844 5092 4459 5706 6004 7407 3817 1672 4132 6727 5514
2013-12-20 5393 3082 1977 1973 1321 1462 1667 974 1222 1423 1818 2954 5261 4082 4889 6194 6355 6755 9276 6215 6275 6152 5849 5959
2013-12-21 4924 3247 1859 1637 1331 1414 1617 1249 1327 2072 2385 2784 2927 2630 2740 2916 2871 3139 6222 5042 4680 4828 4829 4633
2013-12-22 3838 2702 2073 1836 1417 1186 1427 1442 1633 2043 3376 4120 4346 4159 4473 4759 4450 4773 4962 6876 7718 7327 7472 6768
2013-12-23 5260 3316 2134 1776 1258 1231 1672 1299 894 1023 1195 2402 3516 3584 5172 7778 8700 8331 8030 6035 7712 7669 8084 7450
2013-12-24 7098 4150 2293 1774 1205 1189 1589 1476 1145 1733 2023 2678 4647 3835 4571 6430 6943 7864 8863 5181 6080 7125 8609 6496
2013-12-25 4905 2734 1695 1604 1377 1360 1580 1200 1289 1335 2341 4287 5532 4332 5077 6474 6952 7888 7702 3655 6388 9370 9115 8470
2013-12-26 7468 3877 2269 1959 1370 1398 1908 467 39 140 155 143 131 418 1081 2148 8863 8775 8934 8498 9086 8356
2013-12-27 6419 4015 1833 1627 1421 1361 1590 2511 3768 3996 5245 6196 7894 8098 7373 7497 7296 7324 8437 8120 8059 8384 8435 8277
2013-12-28 7678 4543 2619 2041 1587 1568 1726 2539 3578 4911 5945 7082 7563 7343 7916 7529 7863 8234 8165 8076 8528 8763 8670 7892
2013-12-29 6661 4372 2621 1823 1336 1224 1433 2290 3223 4477 5873 7296 7842 7614 7975 8060 8639 8402 8889 8398 8457 8320 9454 8700
2013-12-30 7607 4656 2765 2100 1528 1440 1635 2511 3997 5140 7044 7658 9435 9147 9147 10058 9956 10529 9852 9662 10644 11448 12848 12136
2013-12-31 10349 6155 3885 2703 1900 1803 2110 3586 5362 8051 10713 12249 13035 13001 13298 15048 15950 17235 17573 15644 16229 15365 14898 17461
2014-01-01 22849 15263 4149 3157 4218 4828 7216 15086 7594 12145 27222 2067 2511 2540 2478 4938 9088 14816 21263 7463 1861 4411 10241 9638
2014-01-02 8627 4964 2749 4744 3729 4168 6328 1915 1342 1889 2848 3233 3197 3612 4528 4449 7701 12565 20139 6596 4637 6998 8677 8949
2014-01-03 6857 5227 6151 3906 2678 2656 2899 2227 1378 2470 2706 3105 3573 3287 3754 7378 10992 11090 10936 5549 6432 8894 9887 8318
2014-01-04 6833 4113 2371 2687 2248 2016 2138 1689 1079 1437 1921 2448 2451 4279 7620 8104 8364 8326 7957 6164 5549 5233 5850 8926
2014-01-05 9757 6208 3823 2627 2073 1782 1854 695 419 511 661 1073 1976 2815 3173 3884 9464 11131 11139 9671 9997 10924 9716 10967
2014-01-06 7623 4818 2873 2159 1656 1480 1733 2948 3538 4550 5638 6605 9118 7973 7552 7691 7392 8170 7714 8308 8974 9368 10272 9641
2014-01-07 7025 4124 2604 1800 1488 1417 1647 1235 1434 2369 3146 3886 5686 6811 6426 6926 7317 8297 8453 6858 9441 9961 9958 8910
2014-01-08 7551 3997 2606 1837 1379 1248 1872 886 647 1022 1465 1828 2463 2138 1909 2163 2298 2832 2944 5583 7953 9266 10316 10737
2014-01-09 9161 4801 2999 2361 1871 1734 2094 3674 5135 5177 6758 7622 11370 10181 10548 12154 13235 13557 11017 4679 5650 6648 7858 7154
2014-01-10 5273 3243 1795 1349 1206 1020 1556 673 526 505 698 827 1039 996 1127 1232 2925 5981 10609 1481
提供されたデータの穴がすぐ分かる(多分サーバーが稼働停止していた) 。
上記は、crosstableの出力を、エクセルにコピペし条件付き書式を使った。
18
各都道府県の毎週の感染者数
19
データの出典: 「都道府県別新型コロナウイルス感染者数マップ(ジャッグジャパン株式会社提供)」; https://gis.jag-
japan.com/covid19jp/ からCreative Commons「BY-NC 国際4.0」の条件で、CSVファイルを入手し、8月27日04:06最終更新の
データの40列目の「確定日」の週(日曜始まり)の最初の日付と、42列目の「居住地都道府県」から、二元分割表を作成。
20
https://github.com/tulamili/tinyMathLab/blob/master/resistorcc
各数字に、電気抵抗器のカラーコードに似せて着色。
vm_stat の出力に色を付けた
21
https://github.com/tulamili/tinyMathLab/blob/master/resistorcc
工夫点
と
今の課題
1. 思い出しやすく、使い易く、間違えにくく。
2. プログラム名は英単語2個10文字以内とした。
3. Ctrl + Cで途中結果を出力。すぐ止めない。
4. ANSIカラーを多用(特に標準エラー出力)。
5. 標準エラー出力に、様々な要約情報。
6. 相当古い環境でも使えるようにした。(5.014)
7. 各プログラムに多数の便利な小機能を実装。
 1人で約5年作成。機能の一貫性が不十分かも。
 レポジトリの整理が不十分。
 利用者数やDL数は不明。
 問: データ分析に必要な機能とは何か?
22

More Related Content

Similar to A Hacking Toolset for Big Tabular Files -- JAPAN.PM 2021

寿司blogが書けなくて嵌った話(MySQL/絵文字対応)
寿司blogが書けなくて嵌った話(MySQL/絵文字対応)寿司blogが書けなくて嵌った話(MySQL/絵文字対応)
寿司blogが書けなくて嵌った話(MySQL/絵文字対応)Kenichiro MATOHARA
 
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...Insight Technology, Inc.
 
Talking about delegation_in_powerapps
Talking about delegation_in_powerappsTalking about delegation_in_powerapps
Talking about delegation_in_powerappsShinya Sakakibara
 
MySQL5.6と5.7性能比較
MySQL5.6と5.7性能比較MySQL5.6と5.7性能比較
MySQL5.6と5.7性能比較hiroi10
 
TensorFlow を使った 機械学習ことはじめ (GDG京都 機械学習勉強会)
TensorFlow を使った機械学習ことはじめ (GDG京都 機械学習勉強会)TensorFlow を使った機械学習ことはじめ (GDG京都 機械学習勉強会)
TensorFlow を使った 機械学習ことはじめ (GDG京都 機械学習勉強会)徹 上野山
 
20151107 cfj setohiga4_2
20151107 cfj setohiga4_220151107 cfj setohiga4_2
20151107 cfj setohiga4_2Toshikazu Seto
 
Scis2017 2007-01-27-02
Scis2017 2007-01-27-02Scis2017 2007-01-27-02
Scis2017 2007-01-27-02Ruo Ando
 

Similar to A Hacking Toolset for Big Tabular Files -- JAPAN.PM 2021 (11)

B
BB
B
 
寿司blogが書けなくて嵌った話(MySQL/絵文字対応)
寿司blogが書けなくて嵌った話(MySQL/絵文字対応)寿司blogが書けなくて嵌った話(MySQL/絵文字対応)
寿司blogが書けなくて嵌った話(MySQL/絵文字対応)
 
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...
[db tech showcase Tokyo 2015] A14:Amazon Redshiftの元となったスケールアウト型カラムナーDB徹底解説 その...
 
Code iq interpretation_futatsugi
Code iq interpretation_futatsugiCode iq interpretation_futatsugi
Code iq interpretation_futatsugi
 
Talking about delegation_in_powerapps
Talking about delegation_in_powerappsTalking about delegation_in_powerapps
Talking about delegation_in_powerapps
 
【Slideshare用】資料勉強会
【Slideshare用】資料勉強会【Slideshare用】資料勉強会
【Slideshare用】資料勉強会
 
Stock prediction
Stock predictionStock prediction
Stock prediction
 
MySQL5.6と5.7性能比較
MySQL5.6と5.7性能比較MySQL5.6と5.7性能比較
MySQL5.6と5.7性能比較
 
TensorFlow を使った 機械学習ことはじめ (GDG京都 機械学習勉強会)
TensorFlow を使った機械学習ことはじめ (GDG京都 機械学習勉強会)TensorFlow を使った機械学習ことはじめ (GDG京都 機械学習勉強会)
TensorFlow を使った 機械学習ことはじめ (GDG京都 機械学習勉強会)
 
20151107 cfj setohiga4_2
20151107 cfj setohiga4_220151107 cfj setohiga4_2
20151107 cfj setohiga4_2
 
Scis2017 2007-01-27-02
Scis2017 2007-01-27-02Scis2017 2007-01-27-02
Scis2017 2007-01-27-02
 

More from Toshiyuki Shimono

国際産業数理・応用数理会議のポスター(作成中)
国際産業数理・応用数理会議のポスター(作成中)国際産業数理・応用数理会議のポスター(作成中)
国際産業数理・応用数理会議のポスター(作成中)Toshiyuki Shimono
 
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装Toshiyuki Shimono
 
extracting only a necessary file from a zip file
extracting only a necessary file from a zip fileextracting only a necessary file from a zip file
extracting only a necessary file from a zip fileToshiyuki Shimono
 
新型コロナの感染者数 全国の状況 2021年2月上旬まで
新型コロナの感染者数 全国の状況 2021年2月上旬まで新型コロナの感染者数 全国の状況 2021年2月上旬まで
新型コロナの感染者数 全国の状況 2021年2月上旬までToshiyuki Shimono
 
Multiplicative Decompositions of Stochastic Distributions and Their Applicat...
 Multiplicative Decompositions of Stochastic Distributions and Their Applicat... Multiplicative Decompositions of Stochastic Distributions and Their Applicat...
Multiplicative Decompositions of Stochastic Distributions and Their Applicat...Toshiyuki Shimono
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Toshiyuki Shimono
 
Interpreting Multiple Regression via an Ellipse Inscribed in a Square Extensi...
Interpreting Multiple Regressionvia an Ellipse Inscribed in a Square Extensi...Interpreting Multiple Regressionvia an Ellipse Inscribed in a Square Extensi...
Interpreting Multiple Regression via an Ellipse Inscribed in a Square Extensi...Toshiyuki Shimono
 
BigQueryを使ってみた(2018年2月)
BigQueryを使ってみた(2018年2月)BigQueryを使ってみた(2018年2月)
BigQueryを使ってみた(2018年2月)Toshiyuki Shimono
 
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案Toshiyuki Shimono
 
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...Toshiyuki Shimono
 
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...Toshiyuki Shimono
 
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)Toshiyuki Shimono
 
企業等に蓄積されたデータを分析するための処理機能の提案
企業等に蓄積されたデータを分析するための処理機能の提案企業等に蓄積されたデータを分析するための処理機能の提案
企業等に蓄積されたデータを分析するための処理機能の提案Toshiyuki Shimono
 
新入社員の頃に教えて欲しかったようなことなど
新入社員の頃に教えて欲しかったようなことなど新入社員の頃に教えて欲しかったようなことなど
新入社員の頃に教えて欲しかったようなことなどToshiyuki Shimono
 
ページャ lessを使いこなす
ページャ lessを使いこなすページャ lessを使いこなす
ページャ lessを使いこなすToshiyuki Shimono
 
Guiを使わないテキストデータ処理
Guiを使わないテキストデータ処理Guiを使わないテキストデータ処理
Guiを使わないテキストデータ処理Toshiyuki Shimono
 
データ全貌把握の方法170324
データ全貌把握の方法170324データ全貌把握の方法170324
データ全貌把握の方法170324Toshiyuki Shimono
 
Macで開発環境を整える170420
Macで開発環境を整える170420Macで開発環境を整える170420
Macで開発環境を整える170420Toshiyuki Shimono
 
大きなテキストデータを閲覧するには
大きなテキストデータを閲覧するには大きなテキストデータを閲覧するには
大きなテキストデータを閲覧するにはToshiyuki Shimono
 

More from Toshiyuki Shimono (20)

国際産業数理・応用数理会議のポスター(作成中)
国際産業数理・応用数理会議のポスター(作成中)国際産業数理・応用数理会議のポスター(作成中)
国際産業数理・応用数理会議のポスター(作成中)
 
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装
インターネット等からデータを自動収集するソフトウェアに必要な補助機能とその実装
 
extracting only a necessary file from a zip file
extracting only a necessary file from a zip fileextracting only a necessary file from a zip file
extracting only a necessary file from a zip file
 
新型コロナの感染者数 全国の状況 2021年2月上旬まで
新型コロナの感染者数 全国の状況 2021年2月上旬まで新型コロナの感染者数 全国の状況 2021年2月上旬まで
新型コロナの感染者数 全国の状況 2021年2月上旬まで
 
Multiplicative Decompositions of Stochastic Distributions and Their Applicat...
 Multiplicative Decompositions of Stochastic Distributions and Their Applicat... Multiplicative Decompositions of Stochastic Distributions and Their Applicat...
Multiplicative Decompositions of Stochastic Distributions and Their Applicat...
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...
 
Interpreting Multiple Regression via an Ellipse Inscribed in a Square Extensi...
Interpreting Multiple Regressionvia an Ellipse Inscribed in a Square Extensi...Interpreting Multiple Regressionvia an Ellipse Inscribed in a Square Extensi...
Interpreting Multiple Regression via an Ellipse Inscribed in a Square Extensi...
 
BigQueryを使ってみた(2018年2月)
BigQueryを使ってみた(2018年2月)BigQueryを使ってみた(2018年2月)
BigQueryを使ってみた(2018年2月)
 
Seminar0917
Seminar0917Seminar0917
Seminar0917
 
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案
既存分析ソフトへ
データを投入する前に
簡便な分析するためのソフトの作り方の提案
 
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
 
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
To Make Graphs Such as Scatter Plots Numerically Readable (PacificVis 2018, K...
 
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)
Make Accumulated Data in Companies Eloquent by SQL Statement Constructors (PDF)
 
企業等に蓄積されたデータを分析するための処理機能の提案
企業等に蓄積されたデータを分析するための処理機能の提案企業等に蓄積されたデータを分析するための処理機能の提案
企業等に蓄積されたデータを分析するための処理機能の提案
 
新入社員の頃に教えて欲しかったようなことなど
新入社員の頃に教えて欲しかったようなことなど新入社員の頃に教えて欲しかったようなことなど
新入社員の頃に教えて欲しかったようなことなど
 
ページャ lessを使いこなす
ページャ lessを使いこなすページャ lessを使いこなす
ページャ lessを使いこなす
 
Guiを使わないテキストデータ処理
Guiを使わないテキストデータ処理Guiを使わないテキストデータ処理
Guiを使わないテキストデータ処理
 
データ全貌把握の方法170324
データ全貌把握の方法170324データ全貌把握の方法170324
データ全貌把握の方法170324
 
Macで開発環境を整える170420
Macで開発環境を整える170420Macで開発環境を整える170420
Macで開発環境を整える170420
 
大きなテキストデータを閲覧するには
大きなテキストデータを閲覧するには大きなテキストデータを閲覧するには
大きなテキストデータを閲覧するには
 

A Hacking Toolset for Big Tabular Files -- JAPAN.PM 2021

  • 1. A Hacking Toolset for Big Tabular Files 2021年2月18日(木) 下野寿之 — Toshiyuki Shimono JAPAN.PM 2021 1
  • 2. 内容 (大体の流れ) : 1. Perl やっぱり使い易い!! 2. テーブルデータ用のツール作った 3. 便利! 4. 結局 何したかった? 2
  • 3. Perl II Practical Extraction and Report Language 成熟した機能  文字列処理が器用  括弧をよく省略できる (非教科書的ではある)  浮動小数点演算も 十進数計算も切替が簡単  CPAN — 安心感が高い  数十年後も多分使える → use 5.018 ; と書くだけ テキスト生データをどこでも手際よく 安心して使いたいという観点から. 3
  • 6. (タブ区切り)テキストデータを 容易に扱うCLIを作った。 0. CLI = Command Line Interface (要は黒い画面) 1. CSVデータでもTSVデータでも、分析の為の テーブルの意味理解の作業は意外と大変 !! 2. 前処理などの前のデータ読解ツールを作った。 なぜ作ったか?  シェル芸でも大変だったから。  Excel, R, SQL, Pandas も物足りない。 データ分析の迅速性大事。でも今まで無理だった! 6
  • 7. CLI: Unixコマンドとして(も)使える 7 NAME FUNCTION DETAIL xcol Table looking-up Similar to SQL-join, Unix-join, Excel-vlookup sampler Probabilistic extraction Can specify random seeds, probability weight. keyvalues Key multiplicity Inspects many aspects of a file of “key + value”. kvcmp Check the KV relation When 2 KV files are given, check the sameness. colgrep Column-wise grep More useful than Unix-grep idmaker ID creation Second DB normalization denomfind Finding common denom.Guessing the whole number from the fractions. shuffler Shuffle lines Also an option with preserving the heading line. alluniq Check the uniqueness Also print out how many same lines. expskip Logarithmic extraction Useful for taking a glace at the first stage. eofcheck Check the end of file Important at the initial stage of data analysis task. dirhier Directory structure How many files on each depth. timeput Time stamp on each line When one line comes, time added on its head. 「無いと不便」と思った機能を次々実装。
  • 10. AWKやcutコマンドより便利な 列選択コマンドを作ってみた。 csel コマンドの使い方の例: csel –t 2 ; # 入力2列目を末尾列に移動して出力。 csel –h -1 ; # 入力の末尾列を出力の先頭列に移動。 csel –p 5,7..10 ; # 5列と7,8,9,10列目だけを出力。 csel –d 6..9 ; # 入力の6,7,8,9列目を出力しない。 AWKや Unixのcutコマンドで書くより、簡単。 https://metacpan.org/pod/distribution/Table-Hack/scripts/csel https://github.com/tulamili/bin4tsv/blob/master/cols 10
  • 11. colorplus : 文字/数字に色を付ける wc * | coloplus -3 colorplus (Perlで書かれたプログラム) に標準入力からテキストを渡すと、 -3 のオプションで数字の部分だけ、下から3桁区切りに色を付ける。 数が読みやすくなる。 「 -3 」以外にも多数の有用なオプション(コマンドスイッチ)を用意。-4など。 https://metacpan.org/release/App-colorplus https://github.com/tulamili/bin4tsv/blob/master/colorplus 11
  • 12. colorplus で、5列ごとに背景を着色 colorplus で様々な着色を可能とした。 -t 5 により、列を5列ごとに背景を着色。 他には、 -s で指定した正規表現に着色、-0 で着色の除去など。 詳細未知のデータを与えられて、最初に眺め、意味を把握するときに有用。12 colorplus –t 5 foo | less –N -S
  • 13. crosstable : クロス表(2元分割表) > crosstable foo 2列の表形式データを受け取ると、それをクロス表で出力(タブ文字区切り)。 csv形式も可能。色は除去可能。1行目が変数名の並びでも、対応可能。 他にもいろいろな小機能あり(オプションで指定可能)。 https://metacpan.org/release/CLI-Contingency-Table 13
  • 14. 少しシェル芸的に 2列を取り出して、 クロス集計 ( crosstable )をして、 文字の「0」だけ青色に着色( colorplus –s 0 –b blue)した。 14
  • 15. freq : 頻度表を出力 ( sort | uniq –c の様な動作を高速化/高機能化) 各行の文字列を1件ずつの値と見なし、異なる値が何件出現したかを出力する。 — 出力の、タブ文字で区切って、左に数で件数、右に値。 いろいろな便利機能 : • 15秒ごとに、何行既に読んだかなど、標準エラー出力に情報を出す。 • 最後に標準エラー出力に、何件処理したか、などの便利情報を出す。 https://metacpan.org/pod/distribution/Table-Hack/scripts/freq 15
  • 16. freq : with options For freq, -f for sorting in frequency number, -r for reversing the order, -% for showing the ratio among the whole, -s for cumulative counting, -= for recognizing the heading line (appeared in the previous page.) 16
  • 18. ツイッターの発言のデータの 日付と時間帯で, 個数を集計 日付/時間 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2013-12-10 32 157 153 156 139 161 170 182 315 356 276 221 256 2013-12-11 127 93 64 58 39 72 90 144 200 149 170 116 177 144 170 149 156 268 318 253 216 187 203 235 2013-12-12 136 86 68 63 46 61 64 115 177 134 130 121 463 582 423 442 703 1285 1394 1446 1444 1611 2023 1974 2013-12-13 1532 958 634 478 396 403 526 837 1122 1097 1457 1386 1988 1816 2037 3025 3662 4125 4551 5062 4655 4993 5576 2969 2013-12-14 2873 1626 1139 1018 529 682 807 1164 1655 2115 2536 2715 2868 3454 3720 3812 3611 3438 4202 5005 2557 3133 5031 4274 2013-12-15 3617 2232 1694 1330 1051 974 1173 1732 2590 3549 4942 5871 5306 3056 3571 5247 6666 6798 6964 2597 1710 3382 7879 6425 2013-12-16 4623 2741 1631 1304 927 1094 1185 2053 2597 2474 3415 3614 4580 4836 4187 4999 4115 4122 5957 6427 6328 6793 6545 5963 2013-12-17 4045 2405 1545 1189 1007 946 1237 2692 3532 3435 4178 4925 6158 5049 4756 4375 3890 4138 5090 6265 7628 7077 6639 6325 2013-12-18 4458 2807 1713 1404 1131 1051 1347 1954 2299 2624 3412 2707 1962 1773 1910 3851 5263 6359 7177 6583 6936 6644 6234 6119 2013-12-19 4637 3064 1739 1509 1141 1100 1394 2362 2994 3897 3999 4344 5260 6844 5092 4459 5706 6004 7407 3817 1672 4132 6727 5514 2013-12-20 5393 3082 1977 1973 1321 1462 1667 974 1222 1423 1818 2954 5261 4082 4889 6194 6355 6755 9276 6215 6275 6152 5849 5959 2013-12-21 4924 3247 1859 1637 1331 1414 1617 1249 1327 2072 2385 2784 2927 2630 2740 2916 2871 3139 6222 5042 4680 4828 4829 4633 2013-12-22 3838 2702 2073 1836 1417 1186 1427 1442 1633 2043 3376 4120 4346 4159 4473 4759 4450 4773 4962 6876 7718 7327 7472 6768 2013-12-23 5260 3316 2134 1776 1258 1231 1672 1299 894 1023 1195 2402 3516 3584 5172 7778 8700 8331 8030 6035 7712 7669 8084 7450 2013-12-24 7098 4150 2293 1774 1205 1189 1589 1476 1145 1733 2023 2678 4647 3835 4571 6430 6943 7864 8863 5181 6080 7125 8609 6496 2013-12-25 4905 2734 1695 1604 1377 1360 1580 1200 1289 1335 2341 4287 5532 4332 5077 6474 6952 7888 7702 3655 6388 9370 9115 8470 2013-12-26 7468 3877 2269 1959 1370 1398 1908 467 39 140 155 143 131 418 1081 2148 8863 8775 8934 8498 9086 8356 2013-12-27 6419 4015 1833 1627 1421 1361 1590 2511 3768 3996 5245 6196 7894 8098 7373 7497 7296 7324 8437 8120 8059 8384 8435 8277 2013-12-28 7678 4543 2619 2041 1587 1568 1726 2539 3578 4911 5945 7082 7563 7343 7916 7529 7863 8234 8165 8076 8528 8763 8670 7892 2013-12-29 6661 4372 2621 1823 1336 1224 1433 2290 3223 4477 5873 7296 7842 7614 7975 8060 8639 8402 8889 8398 8457 8320 9454 8700 2013-12-30 7607 4656 2765 2100 1528 1440 1635 2511 3997 5140 7044 7658 9435 9147 9147 10058 9956 10529 9852 9662 10644 11448 12848 12136 2013-12-31 10349 6155 3885 2703 1900 1803 2110 3586 5362 8051 10713 12249 13035 13001 13298 15048 15950 17235 17573 15644 16229 15365 14898 17461 2014-01-01 22849 15263 4149 3157 4218 4828 7216 15086 7594 12145 27222 2067 2511 2540 2478 4938 9088 14816 21263 7463 1861 4411 10241 9638 2014-01-02 8627 4964 2749 4744 3729 4168 6328 1915 1342 1889 2848 3233 3197 3612 4528 4449 7701 12565 20139 6596 4637 6998 8677 8949 2014-01-03 6857 5227 6151 3906 2678 2656 2899 2227 1378 2470 2706 3105 3573 3287 3754 7378 10992 11090 10936 5549 6432 8894 9887 8318 2014-01-04 6833 4113 2371 2687 2248 2016 2138 1689 1079 1437 1921 2448 2451 4279 7620 8104 8364 8326 7957 6164 5549 5233 5850 8926 2014-01-05 9757 6208 3823 2627 2073 1782 1854 695 419 511 661 1073 1976 2815 3173 3884 9464 11131 11139 9671 9997 10924 9716 10967 2014-01-06 7623 4818 2873 2159 1656 1480 1733 2948 3538 4550 5638 6605 9118 7973 7552 7691 7392 8170 7714 8308 8974 9368 10272 9641 2014-01-07 7025 4124 2604 1800 1488 1417 1647 1235 1434 2369 3146 3886 5686 6811 6426 6926 7317 8297 8453 6858 9441 9961 9958 8910 2014-01-08 7551 3997 2606 1837 1379 1248 1872 886 647 1022 1465 1828 2463 2138 1909 2163 2298 2832 2944 5583 7953 9266 10316 10737 2014-01-09 9161 4801 2999 2361 1871 1734 2094 3674 5135 5177 6758 7622 11370 10181 10548 12154 13235 13557 11017 4679 5650 6648 7858 7154 2014-01-10 5273 3243 1795 1349 1206 1020 1556 673 526 505 698 827 1039 996 1127 1232 2925 5981 10609 1481 提供されたデータの穴がすぐ分かる(多分サーバーが稼働停止していた) 。 上記は、crosstableの出力を、エクセルにコピペし条件付き書式を使った。 18
  • 19. 各都道府県の毎週の感染者数 19 データの出典: 「都道府県別新型コロナウイルス感染者数マップ(ジャッグジャパン株式会社提供)」; https://gis.jag- japan.com/covid19jp/ からCreative Commons「BY-NC 国際4.0」の条件で、CSVファイルを入手し、8月27日04:06最終更新の データの40列目の「確定日」の週(日曜始まり)の最初の日付と、42列目の「居住地都道府県」から、二元分割表を作成。
  • 22. 工夫点 と 今の課題 1. 思い出しやすく、使い易く、間違えにくく。 2. プログラム名は英単語2個10文字以内とした。 3. Ctrl + Cで途中結果を出力。すぐ止めない。 4. ANSIカラーを多用(特に標準エラー出力)。 5. 標準エラー出力に、様々な要約情報。 6. 相当古い環境でも使えるようにした。(5.014) 7. 各プログラムに多数の便利な小機能を実装。  1人で約5年作成。機能の一貫性が不十分かも。  レポジトリの整理が不十分。  利用者数やDL数は不明。  問: データ分析に必要な機能とは何か? 22

Editor's Notes

  1. Perl いいぞ! という話
  2. 言いたいことは山ほどあるけれど、要点はこういうことです!