in Jupyter, using Pandas, is there a way to show an entire dataframe in a new tab of the navigator?
When I want to control a dataframe, I usually export it in .csv and then open in Excel.
I am looking for a faster way, but I am not willing to display the full frame into my Notebook, as it make it unreadable.
Since the normal output of a frame is an HTML table, I wonder how we can show this table elsewhere than in the Notebook.
To show the full data without any hiding, you can use pd. set_option('display. max_rows', 500) and pd. set_option('display.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable.
A function set_option() is provided by pandas to display all rows of the data frame. display. max_rows represents the maximum number of rows that pandas will display while displaying a data frame. The default value of max_rows is 10.
You could use javascript
together with ipython.display
to open a new window and show the whole dataframe in it. The advantage is that you can do that several times without the need to create actual HTML files in between or to reload the window. My solution for that question automatically updates the opened window and kind of emulates the View()
function from R/RStudio
:
from IPython.display import HTML
def View(df):
css = """<style>
table { border-collapse: collapse; border: 3px solid #eee; }
table tr th:first-child { background-color: #eeeeee; color: #333; font-weight: bold }
table thead th { background-color: #eee; color: #000; }
tr, th, td { border: 1px solid #ccc; border-width: 1px 0 0 1px; border-collapse: collapse;
padding: 3px; font-family: monospace; font-size: 10px }</style>
"""
s = '<script type="text/Javascript">'
s += 'var win = window.open("", "Title", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));'
s += 'win.document.body.innerHTML = \'' + (df.to_html() + css).replace("\n",'\\') + '\';'
s += '</script>'
return(HTML(s+css))
View(df)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With