pandas pd.options.display.max_rows not working as expected
Question:
I’m using pandas 0.25.1 in Jupyter Lab and the maximum number of rows I can display is 10, regardless of what pd.options.display.max_rows
is set to.
However, if pd.options.display.max_rows
is set to less than 10 it takes effect and if pd.options.display.max_rows = None
then all rows show.
Any idea how I can get a pd.options.display.max_rows
of more than 10 to take effect?
Answers:
Final answer as of pandas v0.25.1
- To display all the rows, set
max_rows
greater than the number of rows in the DataFrame
.
- To display more than 10 rows when the dataframe is truncated, set
min_rows
greater than 10.
- With more than 200 rows of data, if
max_rows
is 200 and min_rows
is 20, 10 from the head and 10 from the tail will be displayed.
- With more than 200 rows of data, if
max_rows
is 200 and min_rows
is None
, 100 from the head and 100 from the tail will be displayed.
Discovery & Notes:
Both pd.set_option('display.max_rows', x)
and pd.options.display.max_rows = x
(where x is some number), should work.
- FYI: the default is 10 rows, as per pandas.set_option
- Options and settings
- This is also in
Jupyter Lab
Other useful pandas
options:
pd.set_option('display.max_columns', 200)
pd.set_option('display.max_rows', 100)
pd.set_option('display.min_rows', 100)
pd.set_option('display.expand_frame_repr', True)
get.options
to return the current value:
pd.get_option("display.max_rows")
Update:
- After some discovery testing, the setting only displays more rows, if the setting is greater than the number of rows in the
DataFrame
.
- If
pd.set_option('display.max_rows', 100)
, but the DataFrame
has 200 rows, only 10 will show up.
- If
pd.set_option('display.max_rows', 200)
, but the DataFrame
has 100 rows, all 100 will display.
Per the pandas docs:
display.max_rows
: default=60
- This sets the maximum number of rows pandas should output when printing out various output. For example, this value determines whether the repr() for a dataframe prints out fully or just a truncated or summary repr. ‘None’ value means unlimited.
display.min_rows
: default=10
- The numbers of rows to show in a truncated repr (when max_rows is exceeded). Ignored when max_rows is set to None or 0. When set to None, follows the value of max_rows.
display.large_repr
: default=truncate
- For DataFrames exceeding
max_rows
/max_cols
, the repr (and HTML repr) can show a truncated table (the default), or switch to the view from df.info()
(the behaviour in earlier versions of pandas). allowable settings, [‘truncate’, ‘info’]
min_rows displays the number of rows to be displayed from the top (head) and from the bottom (tail) it will be evenly split..despite putting in an odd number. If you only want a set number of rows to be displayed without reading it into the memory,
another way is to use nrows = 'putnumberhere'
.
e.g. results = pd.read_csv('ex6.csv', nrows = 5) # display 5 rows from the top 0 - 4
If the dataframe has about 100 rows and you want to display only the first 5 rows from the top…NO TAIL use .nrows
I’m using pandas 0.25.1 in Jupyter Lab and the maximum number of rows I can display is 10, regardless of what pd.options.display.max_rows
is set to.
However, if pd.options.display.max_rows
is set to less than 10 it takes effect and if pd.options.display.max_rows = None
then all rows show.
Any idea how I can get a pd.options.display.max_rows
of more than 10 to take effect?
Final answer as of pandas v0.25.1
- To display all the rows, set
max_rows
greater than the number of rows in theDataFrame
. - To display more than 10 rows when the dataframe is truncated, set
min_rows
greater than 10. - With more than 200 rows of data, if
max_rows
is 200 andmin_rows
is 20, 10 from the head and 10 from the tail will be displayed. - With more than 200 rows of data, if
max_rows
is 200 andmin_rows
isNone
, 100 from the head and 100 from the tail will be displayed.
Discovery & Notes:
Both pd.set_option('display.max_rows', x)
and pd.options.display.max_rows = x
(where x is some number), should work.
- FYI: the default is 10 rows, as per pandas.set_option
- Options and settings
- This is also in
Jupyter Lab
Other useful pandas
options:
pd.set_option('display.max_columns', 200)
pd.set_option('display.max_rows', 100)
pd.set_option('display.min_rows', 100)
pd.set_option('display.expand_frame_repr', True)
get.options
to return the current value:
pd.get_option("display.max_rows")
Update:
- After some discovery testing, the setting only displays more rows, if the setting is greater than the number of rows in the
DataFrame
. - If
pd.set_option('display.max_rows', 100)
, but theDataFrame
has 200 rows, only 10 will show up. - If
pd.set_option('display.max_rows', 200)
, but theDataFrame
has 100 rows, all 100 will display.
Per the pandas docs:
display.max_rows
: default=60- This sets the maximum number of rows pandas should output when printing out various output. For example, this value determines whether the repr() for a dataframe prints out fully or just a truncated or summary repr. ‘None’ value means unlimited.
display.min_rows
: default=10- The numbers of rows to show in a truncated repr (when max_rows is exceeded). Ignored when max_rows is set to None or 0. When set to None, follows the value of max_rows.
display.large_repr
: default=truncate- For DataFrames exceeding
max_rows
/max_cols
, the repr (and HTML repr) can show a truncated table (the default), or switch to the view fromdf.info()
(the behaviour in earlier versions of pandas). allowable settings, [‘truncate’, ‘info’]
min_rows displays the number of rows to be displayed from the top (head) and from the bottom (tail) it will be evenly split..despite putting in an odd number. If you only want a set number of rows to be displayed without reading it into the memory,
another way is to use nrows = 'putnumberhere'
.
e.g. results = pd.read_csv('ex6.csv', nrows = 5) # display 5 rows from the top 0 - 4
If the dataframe has about 100 rows and you want to display only the first 5 rows from the top…NO TAIL use .nrows