173

I want to show all columns in a dataframe in a Jupyter Notebook. Jupyter shows some of the columns and adds dots to the last columns like in the following picture:

Juputer Screenshot

How can I display all columns?

0

7 Answers 7

275

Try the display max_columns setting as follows:

import pandas as pd
from IPython.display import display

df = pd.read_csv("some_data.csv")
pd.options.display.max_columns = None
display(df)

Or

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

Pandas 0.11.0 backwards

This is deprecated but in versions of Pandas older than 0.11.0 the max_columns setting is specified as follows:

pd.set_printoptions(max_columns=500)
3
  • 8
    If you want to make a temporary setting, you can use e.g. with pd.option_context("display.max_rows", 10, "display.max_columns", 5): (see Getting and setting options). Oct 18, 2019 at 14:09
  • This is old but do you happen to know if there is a way to set this by default ?
    – Achille G
    Apr 11, 2023 at 13:11
  • once you execute this, all your display() will fail elsewhere Jul 11, 2023 at 18:41
46

I know this question is a little old but the following worked for me in a Jupyter Notebook running pandas 0.22.0 and Python 3:

import pandas as pd
pd.set_option('display.max_columns', <number of columns>)

You can do the same for the rows too:

pd.set_option('display.max_rows', <number of rows>)

This saves importing IPython, and there are more options in the pandas.set_option documentation: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.set_option.html

2
  • 1
    You can use the None keyword in <number of columns> if you don't know the number of columns beforehand.
    – user2317421
    Aug 7, 2019 at 17:51
  • 1
    For some reason none of the pd.set_option and pd.options.display.max_columns = None worked for me. Only the solution with HTML worked. I'm using Python 3.8.5.0, pandas 1.1.3 and jupyter core=4.6.3 with jupyter-notebook : 6.1.4. Any idea why those solutions are not working?
    – Miranda
    Jan 27, 2021 at 18:27
14

I recommend setting the display options inside a context manager so that it only affects a single output. I usually prefer "pretty" html-output, and define a function force_show_all(df) for displaying the DataFrame df:

from IPython.core.display import display, HTML

def force_show_all(df):
    with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.width', None):
        display(HTML(df.to_html()))

# ... now when you're ready to fully display df:
force_show_all(df)

As others have mentioned, please be cautious to only call this on a reasonably-sized dataframe.

11

Python 3.x for large (but not too large) DataFrames

Maybe because I have an older version of pandas but on Jupyter notebook this work for me

import pandas as pd
from IPython.core.display import HTML

df=pd.read_pickle('Data1')
display(HTML(df.to_html()))
5
  • Tried this but it ruined my jupyter session going out of memory. My PC has SSD and 8 GB RAM memory...
    – FLBKernel
    May 28, 2019 at 15:22
  • @FLBKernel it has not done this to me, maybe your Dataframe is much larger than mine. What was your way out? Did you try another method and worked for you? if so share your knowledge. Thanks.
    – rsc05
    May 29, 2019 at 9:47
  • I haven't found any method yet, but I will let you know as soon as I get to solve this problem. And yes, my Dataframe was probably larger so lets point out that this is not recomendable for large Dataframes
    – FLBKernel
    May 29, 2019 at 10:50
  • 1
    @FLBKernel My data frame was also large. But I did not know to what extent large it can be. I will point it out. Thanks!
    – rsc05
    May 30, 2019 at 11:03
  • Mine has 107.763 rows and 15 columns. We can establish -maybe- that more than about 100k rows and 15 columns this answer is not recomendable. I like the "large (but not too large)" title though :)
    – FLBKernel
    May 30, 2019 at 11:37
8

If you want to show all the rows set like bellow

pd.options.display.max_rows = None

If you want to show all columns set like bellow

pd.options.display.max_columns = None
5

you can use pandas.set_option(), for column, you can specify any of these options

pd.set_option("display.max_rows", 200)
pd.set_option("display.max_columns", 100)
pd.set_option("display.max_colwidth", 200)

For full print column, you can use like this

import pandas as pd
pd.set_option('display.max_colwidth', -1)
print(words.head())

enter image description here

4

This can help you:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.