在 jupyter notebook 中以更大的字体显示 pandas dataframe
Display pandas dataframe with larger font in jupyter notebook
我有一个小型(5 行,3 列)数据框,我可以通过在 jupyter 单元格中调用 df
来显示它。我想放大(字体大小)此输出以用于演示目的。可能吗?
您可以使用 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)
您只需在一行中使用此代码即可:
df.style.set_table_attributes('style="font-size: 17px"')
为了更改笔记本中所有数据框的默认 HTML 样式,而不必将样式单独应用于每个数据框,您有两个选择:
单个笔记本使用魔法函数%%html
:
在笔记本的第一个单元格中输入
%%html
<style>
/* Any CSS style can go in here. */
.dataframe th {
font-size: 18px;
}
.dataframe td {
font-size: 16px;
}
</style>
对于所有笔记本调整Jupyter CSS风格:
添加CSS样式信息
.dataframe th {
font-size: 18px;
}
.dataframe td {
font-size: 16px;
}
到以下文件之一:
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 的方法。
我有一个小型(5 行,3 列)数据框,我可以通过在 jupyter 单元格中调用 df
来显示它。我想放大(字体大小)此输出以用于演示目的。可能吗?
您可以使用 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)
您只需在一行中使用此代码即可:
df.style.set_table_attributes('style="font-size: 17px"')
为了更改笔记本中所有数据框的默认 HTML 样式,而不必将样式单独应用于每个数据框,您有两个选择:
单个笔记本使用魔法函数
%%html
:在笔记本的第一个单元格中输入
%%html <style> /* Any CSS style can go in here. */ .dataframe th { font-size: 18px; } .dataframe td { font-size: 16px; } </style>
对于所有笔记本调整Jupyter CSS风格:
添加CSS样式信息
.dataframe th { font-size: 18px; } .dataframe td { font-size: 16px; }
到以下文件之一:
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 的方法。