1

I have a dataframe with 167 columns. When I print df.columns, it shows ... in the list indicating some columns are collapsed from the print.

I tried

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

but this didn't help. How can I display all the columns?

Vitalizzare
  • 4,496
  • 7
  • 13
  • 32
24n8
  • 1,898
  • 1
  • 12
  • 25
  • @itprorh66 I looked at the accepted answer and I think the solution there is equivalent to what I tried above – 24n8 Aug 10 '23 at 14:52
  • The accepted answer does not cover it but multiple of the other answers do. – TylerH Aug 11 '23 at 21:46

1 Answers1

1

This is controlled by the display.max_seq_items parameter. If you type:

help(pd.set_option)

you can see available parameters and their description. As for this one:

display.max_seq_items : int or None
    When pretty-printing a long sequence, no more then `max_seq_items`
    will be printed. If items are omitted, they will be denoted by the
    addition of "..." to the resulting string.

    If set to None, the number of items to be printed is unlimited.
    [default: 100] [currently: 100]

Therefore, in order to display all columns by print(df.columns), you must specify:

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

Or, alternatively, output a list whose printing is not controlled by Pandas:

print(df.columns.tolist())
Vitalizzare
  • 4,496
  • 7
  • 13
  • 32