Scroll through output?

58 views
Skip to first unread message

John E

unread,
Oct 25, 2021, 5:09:33 PM10/25/21
to PyData
Really dumb question but I've never figured this out...  As part of the data exploration stage, I often want to simply scroll through the rows.  In pandas, if I try to print out too many rows, I'll just see the first few and the last few.

What I really want is to just pipe the output through "less" as in bash, but I can't find a way to do this in ipython or jupyter qtconsole.

Pseudocode (mixing pandas and bash):

   print(df) | less

Josh Friedlander

unread,
Oct 26, 2021, 5:05:31 AM10/26/21
to pyd...@googlegroups.com
Of course you can set pd.options.display.max_rows = len(df), which is convenient but can be really slow with big dataframes.

My personal habit for this is to use a separate program for browsing CSVs:
  • My choice is Tad, which is FOSS and cross-platform
  • if you don't like Electron looks like gCSVedit might also work
  • RStudio also provides a better dataframe viewing experience

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pydata/98a5e84a-8368-44c9-b372-6a34bdce979bn%40googlegroups.com.

John E

unread,
Oct 26, 2021, 8:37:08 AM10/26/21
to PyData
Thanks, these are good suggestions, although not quite the ideal to me.

Just increasing max_rows is definitely one way. I guess it's really not much different than paging via "| pipe" in bash. Mainly I prefer a pure command line interface without taking my hands off the keyboard.  Also, it quickly fills up the keyboard buffer.

The other suggestions are good too, just not as good as being able to do a less-style pager to me.  I actually end up doing more of the initial data exploration in Stata because one thing it's interface does better (maybe the only thing though) is to allow me to page through rows less-style (it's sort of a very barebones version of less where the "b" and "/" keys don't work, but still closer to what I want than ipython/jupyter qtconsole).

Jonathan Gutow

unread,
Oct 26, 2021, 8:45:57 AM10/26/21
to PyData
Within Jupyter this works for me:
```
from IPython.display import HTML
tbldiv = '<div style="height:10em;">' + str('Table Title')
tbldiv += str(pandadf.to_html()) + '</div>'
display(HTML(tbldiv))
```
It provides a scrolling window of the whole dataframe in the output of the cell. You can adjust the window height by changing that parameter.

John E

unread,
Oct 26, 2021, 11:36:00 AM10/26/21
to PyData
Thanks, Jonathan.  That looks like an improvement and I'll try it out although I really would like something for a pure console (ipython or jupyter qtconsole) at a bash prompt.

John E

unread,
Oct 26, 2021, 12:08:32 PM10/26/21
to PyData
Oh...  %page is a ipython magic but it's not as automated as would be nice.  E.g. you can do:

   %page df

but not, say,

   %page df[mask]

It will only take a simple object as an argument here, and you have to reset pd.options.display.max_rows as noted by joshua.  But beyond that it seems to work the same as less (with ability to use "b", "/", etc.)

Reply all
Reply to author
Forward
0 new messages