8

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?

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
7

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)

2 Comments

Works nicely. Thanks! :)
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).
3

You can simply use this code in one line:

df.style.set_table_attributes('style="font-size: 17px"')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.