1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Jupyterでpd.DataFrameの出力をスクロール可能にする

Posted at

以下のプログラムをjupyterのセルで実行すると,セルの出力がスクロールが可能になる.

import pandas as pd

def custom_dataframe_display(df):
    return df.style.set_table_styles([
        {'selector': '', 
         'props': [('max-height', '500px'), # スクロールの縦幅
                  ('overflow-y', 'scroll'),
                  ('display', 'block')]
        },
        {'selector': 'thead th', 
         'props': [('position', 'sticky'),
                  ('top', '0'),
                  ('background', '#303030'),  # ヘッダーの背景色
                  ('z-index', '1')]  # 他の要素より前面に表示
        }
    ])

# DataFrameの表示形式をカスタマイズ
pd.DataFrame._repr_html_ = lambda self: custom_dataframe_display(self)._repr_html_()
1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?