-
Notifications
You must be signed in to change notification settings - Fork 7
Tabulated pager cheat sheet and paging lists and Pandas DataFrames with pydoc's pager
Louis Maddox edited this page Sep 8, 2020
·
6 revisions
-
column -tautomatically sets column width in TSV - there's also a way to specify width (not column?) which I can't remember...
-
less -Ssets the pager to not wrap, entering a number (e.g. 4) then the right arrow moves rightwards 4 characters off-screen at a time
If you export PAGER as less -S in your .bashrc:
# for Python with pydoc.pager in ~/.pythonrc :: listpager()
export PAGER='less -S'Then you can set up the following Python functions (I put them in my ~/.pythonrc which loads in every Python session*)
from pydoc import pager
from pandas import option_context
def listpager(a_list):
pager("\n".join([i if type(i) is str else repr(i) for i in a_list]))
def dfpager(dataframe):
with option_context('display.max_rows', None, 'display.max_columns', None):
listpager([dataframe.to_string()])listpager lets you page a list (or any long string) using the system pager, and the dfpager function does the same for pandas DataFrames. I use these all the time now!
* Note that this means you must have pandas in every environment... but if you use it a lot that might be OK!