Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I would like to enlarge (font size) this output for presentation purpose. Is it possible?

like image 946
matt525252 Avatar asked Nov 11 '19 12:11

matt525252


2 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:

  1. 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>
    
  2. 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.

like image 41
Carsten König Avatar answered Oct 20 '22 11:10

Carsten König


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)
like image 71
Zeeshan Avatar answered Oct 20 '22 10:10

Zeeshan