7

Where can I configure Jupyter to make a DataFrame object appear as a full-bordered table by default?

Now it looks like this:

enter image description here

I wish it could look like: enter image description here

Indominus
  • 1,228
  • 15
  • 31

1 Answers1

9

You can add the following code to your notebook, which will apply to all cells in the current notebook regardless of what cell it's entered in:

%%HTML
<style type="text/css">
    table.dataframe td, table.dataframe th {
        border-style: solid;
    }
</style>

If you want it to apply to all notebooks, you can add a custom config/css file. Answers on how to do that can be found here.

You might also want to explore jupyterthemes depending on how much other configuration you want to do.

ZaxR
  • 4,896
  • 4
  • 23
  • 42
  • I tried this solution, but seems what it did was to remove all the line numbers in [] – Indominus Feb 15 '18 at 01:55
  • Can you clarify what you're looking for? I read your question as looking to get rid of the In[] and Out[]. Rereading, are you just looking to add an outer border to dataframes in the output? – ZaxR Feb 15 '18 at 01:57
  • Sorry about that, edited question. Basically, I want full borders around all table cells. – Indominus Feb 15 '18 at 02:04
  • Gotcha. See the updated answer. Basically the answer to any question like this is if you want to do it from the jupyter notebook side is going to be to use CSS. Pandas also has pd.set_option('html.border', 1) and pd.options... but not sure how to get either of those to work. – ZaxR Feb 15 '18 at 02:23
  • 1
    Thank you! It works. I also followed the instructions in the first link you provided (included at the bottom of my comment). It also works. Note: no need to restart Jupyter everytime you change the css file, just need to restart the notebook you are running. https://stackoverflow.com/questions/21971449/how-do-i-increase-the-cell-width-of-the-jupyter-ipython-notebook-in-my-browser – Indominus Feb 15 '18 at 02:25
  • 4
    awesome! with `border: 1px solid lightgray;` tables look perfect! – ccpizza Jun 06 '18 at 19:29
  • Use this logic to make the **font smaller** and it's SO much easier to read now. Thanks! – S3DEV Jul 30 '19 at 09:01
  • I would like to apply this to only one output and not through the entire notebook. Is this possible? – Newbielp Dec 23 '20 at 13:01
  • Instead of using the %%HTML cell magic, you can use display/HTML. See https://stackoverflow.com/a/35760941/7619676 – ZaxR Dec 23 '20 at 15:51