[英]Display pandas dataframe with larger font in jupyter notebook
I have a small-shaped (5 rows, 3 columns) dataframe which I can display by calling df
in jupyter cell.我有一个小形状(5 行,3 列)dataframe,我可以通过在 jupyter 单元格中调用
df
来显示它。 I would like to enlarge (font size) this output for presentation purpose.我想放大(字体大小)这个 output 用于演示目的。 Is it possible?
可能吗?
You can play around with styles using df.style.set_table_styles()
您可以使用
df.style.set_table_styles()
玩弄 styles
This might help:这可能会有所帮助:
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)
You can simply use this code in one line:您可以简单地在一行中使用此代码:
df.style.set_table_attributes('style="font-size: 17px"')
In order to change the default HTML style for all dataframes in a notebook and not having to apply the style individually to each dataframe, you have two options:为了更改笔记本中所有数据帧的默认 HTML 样式,并且不必将样式单独应用于每个 dataframe,您有两个选择:
For a single notebook use the magic function %%html
:对于单个笔记本,请使用魔法 function
%%html
:
In the first cell of your notebook put在笔记本的第一个单元格中
%%html <style> /* Any CSS style can go in here. */.dataframe th { font-size: 18px; }.dataframe td { font-size: 16px; } </style>
For all notebooks adjust the Jupyter CSS style:对于所有笔记本,调整 Jupyter CSS 样式:
Add the CSS style information添加 CSS 样式信息
.dataframe th { font-size: 18px; }.dataframe td { font-size: 16px; }
to one of the following files:到以下文件之一:
Jupyter Notebook : Jupyter 笔记本:
$HOME/.jupyter/custom/custom.css $HOME/.jupyter/custom/custom.css
JupyterLab (depending on the theme): JupyterLab (取决于主题):
$HOME/anaconda3/envs/[ENVIRONMENT NAME]/share/jupyter/lab/themes/@jupyterlab/theme-dark-extension/index.css $HOME/anaconda3/envs/[环境名称]/share/jupyter/lab/themes/@jupyterlab/theme-dark-extension/index.css
or或者
$HOME/anaconda3/envs/[ENVIRONMENT NAME]/share/jupyter/lab/themes/@jupyterlab/theme-light-extension/index.css $HOME/anaconda3/envs/[环境名称]/share/jupyter/lab/themes/@jupyterlab/theme-light-extension/index.css
For the JupyterLab the custom.css is unfortunateley not used, so I do not see another way to change the CSS.对于 JupyterLab,不幸的是没有使用 custom.css,所以我看不到另一种更改 CSS 的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.