为了更改笔记本中所有数据帧的默认 HTML 样式,并且不必将样式单独应用于每个数据帧,您有两种选择:
对于单个笔记本,请使用神奇功能%%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)
对于所有笔记本,调整 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 的方法。
您可以使用以下方式尝试样式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)
| 归档时间: |
|
| 查看次数: |
4351 次 |
| 最近记录: |