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?
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.
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)
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.
within cell/scope only to keep defaults
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
display(df)
© 2022 - 2024 — McMap. All rights reserved.
df.to_clipboard(sep='\\s+', index=False)
– Horseshoes