I have a small-shaped (5 rows, 3 columns) dataframe which I can display by calling df
in jupyter cell. I would like to enlarge (font size) this output for presentation purpose. Is it possible?

- 34,399
- 18
- 41
- 57

- 642
- 1
- 14
- 21
3 Answers
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:
For a single notebook use the magic 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:
Add the CSS style information
.dataframe th { font-size: 18px; } .dataframe td { font-size: 16px; }
to one of the following files:
Jupyter Notebook:
$HOME/.jupyter/custom/custom.css
JupyterLab (depending on the theme):
$HOME/anaconda3/envs/[ENVIRONMENT NAME]/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
For the JupyterLab the custom.css is unfortunateley not used, so I do not see another way to change the CSS.

- 3,413
- 2
- 18
- 16
-
the above code (1) works well but the issue is that the table's index font size seems unaffected. Is there a workaround for setting the index size the same as cell size? – SoakingHummer Nov 18 '22 at 15:10
You can play around with styles using df.style.set_table_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)

- 1,078
- 9
- 14
-
-
it should be noted that `dict(selector="th", props=heading_properties)` is the same as `{"selector": "th", "props": heading_properties}`, and that the backslash at the end of the line is not needed when inside square brackets (or braces or parentheses). – Walter Tross Apr 23 '22 at 14:57
You can simply use this code in one line:
df.style.set_table_attributes('style="font-size: 17px"')

- 171
- 2
- 11