pandasのdataframeがちっこ過ぎて、おっさんで老眼の人間には米粒に書いてある文字を読むのに等しいので、テーブルの文字をでかくする方法をあれこれネットで探索してみた。以下がその結果だ。
スポンサーリンク
dataframeの文字拡大方法¶
%download https://raw.githubusercontent.com/pandas-dev/pandas/master/pandas/tests/data/iris.csv
import pandas as pd
%matplotlib inline
from IPython.display import HTML
iris=pd.read_csv("iris.csv")
styles = [
dict(selector="th", props=[("font-size", "100%"),
("text-align", "center")])
]
html = (iris.head().style.set_table_styles(styles))
html
上のように、とにかくテーブルが小さ過ぎて、テーブル内の文字は解読不能である。
CSSで数字を拡大する¶
from IPython.core.display import display, HTML
css = """
table.dataframe {
font-size: 1.5em;
}
"""
display(HTML('<style>{}</style>'.format(css)))
iris.head()
以上のように、CSSを使えば非常に簡単にテーブル内の数字や文字のフォントを変えられ、老眼親父でも見やすいテーブルを作成することができる。
スポンサーリンク
スポンサーリンク