LoginSignup
16
8

More than 5 years have passed since last update.

DataFrameをmarkdownの表形式に変換するには?(pytablewriter)

Last updated at Posted at 2019-01-31

概要

DataFrameをmarkdownの表形式に変換するには?
⇒ pytablewriter モジュールが便利

利用方法:


import pytablewriter

writer = pytablewriter.MarkdownTableWriter()
writer.from_dataframe(df)
writer.write_table()

出力結果例:

|   name    |PRICE| IV  |
|-----------|----:|----:|
|0201/C20250|  525|23.01|
|0201/C20375|  400|18.19|
|0201/C20500|  280|17.68|
name PRICE IV
0201/C20250 525 23.01
0201/C20375 400 18.19
0201/C20500 280 17.68

参考

pytablewriter

コメント:

pytablewriterはかなり高機能みたいだけど、DataFrameのINDEXを表に反映させ方がわからなかった ⇒ DataFrameにINDEXと同様の内容の列を作成して暫定的に対処。

追記(2月11日): 

ライブラリ作者様が,「add_index_column=True」のオプションで
Index列を追加できる新バージョンを公開してくださいました。
(私のブログにまでコメント頂き、大変恐縮です。
大変有用なライブラリ作成&更新して頂き、まことにありがとうございます)

16
8
2

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
16
8