在 jupyter notebook 中显示大字体的 Pandas 数据框

mat*_*252 5 python dataframe pandas jupyter

我有一个小型(5 行 3 列)数据df框,我可以通过调用jupyter 单元格来显示它。我想放大(字体大小)这个输出用于演示目的。是否可以?

Car*_*nig 7

为了更改笔记本中所有数据帧的默认 HTML 样式,并且不必将样式单独应用于每个数据帧,您有两种选择:

  1. 对于单个笔记本,请使用神奇功能%%html

    在笔记本的第一个单元格中放入

    %%html
    <style>
    /* Any CSS style can go in here. */
    .dataframe th {
        font-size: 18px;
    }
    .dataframe td {
        font-size: 16px;
    }
    </style>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 对于所有笔记本,调整 Jupyter CSS 样式:

    添加CSS样式信息

    .dataframe th {
        font-size: 18px;
    }
    .dataframe td {
        font-size: 16px;
    }
    
    Run Code Online (Sandbox Code Playgroud)

    到以下文件之一:

    • Jupyter 笔记本

      $HOME/.jupyter/custom/custom.css

    • JupyterLab(取决于主题):

      $HOME/anaconda3/envs/[环境名称]/share/jupyter/lab/themes/@jupyterlab/theme-dark-extension/index.css

      或者

      $HOME/anaconda3/envs/[环境名称]/share/jupyter/lab/themes/@jupyterlab/theme-light-extension/index.css

      对于 JupyterLab,不幸的是没有使用 custom.css,所以我没有看到另一种更改 CSS 的方法。


Zee*_*han 6

您可以使用以下方式尝试样式df.style.set_table_styles()

这可能有帮助:

heading_properties = [('font-size', '18px')]

cell_properties = [('font-size', '16px')]

dfstyle = [dict(selector="th", props=heading_properties),\
 dict(selector="td", props=cell_properties)]

df.style.set_table_styles(dfstyle)
Run Code Online (Sandbox Code Playgroud)