323

I have a problem viewing the following DataFrame:

n = 100
foo = DataFrame(index=range(n))
foo['floats'] = np.random.randn(n)
foo

The problem is that it does not print all rows per default in ipython notebook, but I have to slice to view the resulting rows. Even the following option does not change the output:

pd.set_option('display.max_rows', 500)

Does anyone know how to display the whole array?

Ninjakannon
  • 3,751
  • 7
  • 53
  • 76
Andy
  • 9,483
  • 12
  • 38
  • 39
  • 1
    When I run your code in a default (i.e. no special configuration profile) notebook, I get a pretty printed table that is scrollable with all values. FYI, my pandas.__version__ = 0.9.1 (not sure if this matters) – BubbleGuppies May 07 '13 at 18:12
  • I meant regular shell, not ipython – Ryan Saxe May 07 '13 at 18:36
  • I have a feeling this might be a bug in 0.11+... – Andy Hayden May 07 '13 at 21:25
  • Hi Andy. Has this already been confirmed by Wes? Where can I file this bug? Is there a workaround? – Andy May 07 '13 at 21:48
  • I just filed it [here](https://github.com/pydata/pandas/issues/3541), I know there were some last minute changes in 0.11 to the DataFrame repr so I cc'd those in the bug report. Will let you know re workaround. – Andy Hayden May 07 '13 at 21:56
  • For those interested in setting options directly by their attributes, [look at this answer below](https://stackoverflow.com/a/47113685/3707607). – Ted Petrou Nov 04 '17 at 17:50

10 Answers10

526

Set display.max_rows:

pd.set_option('display.max_rows', 500)

For older versions of pandas (<=0.11.0) you need to change both display.height and display.max_rows.

pd.set_option('display.height', 500)
pd.set_option('display.max_rows', 500)

See also pd.describe_option('display').

You can set an option only temporarily for this one time like this:

from IPython.display import display
with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    display(df) #need display to show the dataframe when using with in jupyter
    #some pandas stuff

You can also reset an option back to its default value like this:

pd.reset_option('display.max_rows')

And reset all of them back:

pd.reset_option('all')

ihightower
  • 3,093
  • 6
  • 34
  • 49
Wouter Overmeire
  • 65,766
  • 10
  • 63
  • 43
  • 8
    +1 for the pd.describe_option('display'), I did not know all the options – nom-mon-ir May 08 '13 at 19:08
  • 42
    Height is now deprecated so the display.max_rows option is enough. – hanleyhansen Jun 09 '14 at 16:12
  • 13
    For anyone only looking at the accepted answer: use `with pd.option_context('display.height', 500, 'display.max_rows', 500):` to only set these temporarily. – BallpointBen May 21 '18 at 20:53
  • I should correct or give the best way to achieve this. Use None and don't limit to 500. #Temporary display all rows and columns with pd.option_context('display.max_rows',None, 'display.max_columns', None): display(df_facilities) The above code will take effect only in the cell containing the code so no need to reset in other cells. – MGB.py Jan 23 '20 at 14:03
  • 12
    Not sure if it's a jupyter lab problem, but none of this is working. Only 'display.max_rows' = None does. – antonavy Nov 23 '20 at 16:41
  • 4
    @antonavy I don't know if that is your issue but when setting `display.max_rows` to an integer, setting also `display.min_rows` is needed to affect how many rows are displayed in a truncated view (when `max_rows` is exceeded). – Jan Joswig Jun 07 '21 at 09:25
  • In newest versions of Pandas setting the `display.height` raises an exception now. – Roland Pihlakas Dec 26 '21 at 15:42
  • This is terrible, unusable. Would it be so difficult to add a parameter `display(this, n_rows=2 zillions)`? – Antonio Sesto Mar 09 '22 at 10:00
  • have made this a utility for my jupyter setup. – mr.xed Dec 13 '22 at 18:47
  • With newer versions of Pandas, you can use the slightly less visually distracting `pd.options.display.max_rows = 500` – Josiah Yoder Aug 03 '23 at 18:43
  • Also, setting [`min_rows`](https://stackoverflow.com/a/57861411/1048186) to the same value as `max_rows` seems to work well: dataframes less than `min_rows` still use fewer-than-min rows, and dateframes with more than `max_rows` use `min_rows` in their collapsed form. – Josiah Yoder Aug 03 '23 at 18:51
  • But even at a command prompt, I recommend using the option context as it can quickly become tedious to see all that output except in the few places you want it, especially for `min_rows`. e.g. `with pd.option_context('display.max_rows', 100,'display.min_rows', 100): print(df)` – Josiah Yoder Aug 04 '23 at 15:13
71

Personally, I like setting the options directly with an assignment statement as it is easy to find via tab completion thanks to iPython. I find it hard to remember what the exact option names are, so this method works for me.

For instance, all I have to remember is that it begins with pd.options

pd.options.<TAB>

enter image description here

Most of the options are available under display

pd.options.display.<TAB>

enter image description here

From here, I usually output what the current value is like this:

pd.options.display.max_rows
60

I then set it to what I want it to be:

pd.options.display.max_rows = 100

Also, you should be aware of the context manager for options, which temporarily sets the options inside of a block of code. Pass in the option name as a string followed by the value you want it to be. You may pass in any number of options in the same line:

with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    some pandas stuff

You can also reset an option back to its default value like this:

pd.reset_option('display.max_rows')

And reset all of them back:

pd.reset_option('all')

It is still perfectly good to set options via pd.set_option. I just find using the attributes directly is easier and there is less need for get_option and set_option.

Ted Petrou
  • 59,042
  • 19
  • 131
  • 136
  • 6
    `with pd.option_context` is the cleanest method among these answers; least side effects. – ijoseph Jan 23 '18 at 19:53
  • I guess it depends on what you are doing in your notebook, but I did find the context manager so useful that I wrapped it in a function and used `display(df)` within. – wellplayed Feb 11 '22 at 10:12
69
pd.set_option('display.max_rows', 500)
df

Does not work in Jupyter!
Instead use:

pd.set_option('display.max_rows', 500)
df.head(500)
Adrien Renaud
  • 2,439
  • 18
  • 22
  • 9
    In https://github.com/pandas-dev/pandas/issues/28654#issuecomment-536094705 is an explanation, why that happens. You have to set also `display.min_rows`, because `display.max_rows` is the threshold, when you display `display.min_rows` number of roles. I have no idea, how they came up with these names. – Christoph Boeddeker Sep 15 '21 at 15:28
  • 2
    The first line now seems to work in jupyter notebook without the head() trick. – questionto42 Dec 03 '21 at 15:55
  • 1
    The first one works if len(df) < 500 – konchy Jul 18 '23 at 11:53
17

It was already pointed in this comment and in this answer, but I'll try to give a more direct answer to the question:

from IPython.display import display
import numpy as np
import pandas as pd

n = 100
foo = pd.DataFrame(index=range(n))
foo['floats'] = np.random.randn(n)

with pd.option_context("display.max_rows", foo.shape[0]):
    display(foo)

pandas.option_context is available since pandas 0.13.1 (pandas 0.13.1 release notes). According to this,

[it] allow[s] you to execute a codeblock with a set of options that revert to prior settings when you exit the with block.

17

I don't know why nobody mentioned this.

You should also set 'display.min_rows'.

pd.set_option('display.min_rows', 500)  # <-add this!
pd.set_option('display.max_rows', 500)

If total number of rows > display.max_rows,

then, setting only display.max_rows would not work.

(Yeah, it's confusing. This should be modified.)

starriet
  • 2,565
  • 22
  • 23
16

to set unlimited number of rows use

None

i.e.,

pd.set_option('display.max_columns', None)

now the notebook will display all the rows in all datasets within the notebook ;)

Similarly you can set to show all columns as

pd.set_option('display.max_rows', None)

now if you use run the cell with only dataframe with out any head or tail tags as

df

then it will show all the rows and columns in the dataframe df

arun
  • 461
  • 4
  • 7
9

As @hanleyhansen noted in a comment, as of version 0.18.1, the display.height option is deprecated, and says "use display.max_rows instead". So you just have to configure it like this:

pd.set_option('display.max_rows', 500)

See the Release Notes — pandas 0.18.1 documentation:

Deprecated display.height, display.width is now only a formatting option does not control triggering of summary, similar to < 0.11.0.

nealmcb
  • 12,479
  • 7
  • 66
  • 91
5

As in this answer to a similar question, there is no need to hack settings. It is much simpler to write:

print(foo.to_string())
Ninjakannon
  • 3,751
  • 7
  • 53
  • 76
4

I would use a context manager to set these options so that I can control which df should be affected.

with pd.option_context('display.min_rows', 50, 'display.max_columns', None):
    display(df)

Also, instead of display.max_rows use display.min_rows instead. This should work without setting display.max_rows.

cbare
  • 12,060
  • 8
  • 56
  • 63
3

pd.options.display.max_rows = None

This would display all the rows

mentalist
  • 41
  • 7