LoginSignup
19
3

More than 1 year has passed since last update.

Elixir Explorer のテーブルを見やすく表示する

Last updated at Posted at 2022-08-02

はじめに

以前の記事において、 Elixir の Livebook 上で Explorer を使ったデータ分析を実行しました

ただ、その時使った DataFrame.table() が非常に見づらかったため、見やすく表示する方法を紹介します


2022/11/16 更新

DataFrame.to_rows() を挟む必要がなくなった(もしくは最初からなかった?)ので省きます


実装コードはこちら

変更前の実装(DataFrame.table())

Explorer の DataFrame.table() を使っています

limit: :infinity で全件表示指定しています

テキストでテーブルを作って表示していますが、ガタガタで見づらいです

DataFrame.table(population_df, limit: :infinity)

スクリーンショット 2022-08-02 15.43.05.png

変更後の実装(Kino.DataTable.new())

Kino は Livebook 上の出力をリッチにしてくれるパッケージです

Kino の DataTable.new() にデータフレームを渡すだけでキレイに表示してくれます

population_df
|> Kino.DataTable.new(sorting_enabled: true)

スクリーンショット 2022-11-16 9.33.47.png

スッキリしましたね

右上にページネーションも付きます

しかも、 sorting_enabled: true を指定することで、
列名をクリックするとソートしてくれます

スクリーンショット 2022-08-02 15.47.37.png

相関行列などで列名の順番が重要な場合は、
keys: で指定すればその通りに表示してくれます

スクリーンショット 2022-11-16 9.35.45.png

まとめ

Livebook はまだまだ進化しているので、今後も期待大ですね

19
3
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
3