pandas DataFrame not honoring display.precision in column headers

248 views
Skip to first unread message

Paul Blelloch

unread,
Aug 16, 2017, 10:21:14 PM8/16/17
to Project Jupyter
I'm finding that when I have a pandas DataFrame with float column headers, they don't honor the display.precision option (or display.float_format or set_eng_fload_format) in a jupyter notebook, while they do in an iPython console.  The following is a snippet of code that illustrates the issue:

import pandas as pd
import numpy as np
pd.options.display.precision = 3
labels = np.random.rand(10)
p = pd.DataFrame(np.random.randn(10,10),index=labels,columns=labels)
p

Paul Blelloch

unread,
Aug 16, 2017, 10:40:54 PM8/16/17
to Project Jupyter
To give a little more context; it appears that a MultiIndex works fine.  So the following works just fine:

import pandas as pd
import numpy as np
pd.options.display.precision = 3
labels = pd.MultiIndex.from_arrays((np.random.rand(10),np.random.rand(10)))
p = pd.DataFrame(np.random.randn(10,10),index=labels,columns=labels)
p

So it appears to me that it's only a straight forward float index for columns that doesn't work.  Am I just missing something obvious?

Paul Blelloch

unread,
Aug 16, 2017, 11:35:15 PM8/16/17
to Project Jupyter
I did find a "workaround."  That was to set options.display.notebook_repr_html to False.  This gets rid of the nice HTML table formatting in a notebook, but also fixes the precision problem.  So presumably this means that the issue with the notebook_repr_html option, and this is a Pandas issue and not a jupyter issue.


On Wednesday, August 16, 2017 at 7:21:14 PM UTC-7, Paul Blelloch wrote:
Reply all
Reply to author
Forward
0 new messages