Display full Pandas dataframe in Jupyter without index
Asked Answered
B

4

6

I have a pandas dataframe that I would like to pretty-print in full (it's ~90 rows) in a Jupyter notebook. I'd also like to display it without the index column, if possible. How can I do that?

Bassist answered 3/8, 2020 at 17:25 Comment(3)
Does this answer your question? How do I expand the output display to see more columns of a pandas DataFrame?. It covers rows and columnsHorseshoes
Thanks @TrentonMcKinney - it helps for showing the full dataframe, but what about not displaying the index column?Bassist
I do not think removing the index is an option unless you're printing to the clipboard like df.to_clipboard(sep='\\s+', index=False)Horseshoes
M
5

For pretty-printing without an index, I think the right approach is to call the display method for HTML (which is what jupyter does under the hood):

from IPython.display import HTML

HTML(df.to_html(index=False))

(Credit to Display pandas dataframe without index)

As others have suggested you can use pd.display_max_rows() for the row count limitation.

Mahican answered 6/12, 2021 at 3:25 Comment(0)
V
4

In pandas you can use this

pd.set_option("display.max_rows", None, "display.max_columns", None)

please use this.

Without index use additionally.

df.to_string(index=False)
Valida answered 3/8, 2020 at 18:0 Comment(1)
What about displaying it without the index column?Bassist
H
0

When I want to omit the index, I convert to a styled data frame.

styled_df = df.style.format()
styled_df.hide()

.hide() gets rid of the index. You can also pass format mapping to the to get a nicer pretty print. Assuming you're formatting columns titled 'cashflow' and 'excess', that could look something like

format_mapping = {
    'cashflow': lambda x: f'{x:,.0f}',
    'excess': lambda x: f'{x:,.3f}'
}
styled_df = df.style.format(format_mapping)
styled_df.hide()

You can even do conditional formatting and other fun things with this approach.

Hayrick answered 19/2 at 1:44 Comment(0)
S
0

within cell/scope only to keep defaults

with pd.option_context('display.max_rows', None, 'display.max_columns', None):
    display(df)
Selig answered 8/6 at 18:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.