How to show all of columns name on pandas dataframe?

后端 未结 13 2014
既然无缘
既然无缘 2020-12-07 08:24

I have a dataframe that consist of hundreds of columns, and I need to see all column names.

What I did:

In[37]:
data_all2.columns

T

相关标签:
13条回答
  • 2020-12-07 08:56

    In the interactive console, it's easy to do:

    data_all2.columns.tolist()
    

    Or this within a script:

    print(data_all2.columns.tolist())
    
    0 讨论(0)
  • 2020-12-07 08:56

    What worked for me was the following:

    pd.options.display.max_seq_items = None
    

    You can also set it to an integer larger than your number of columns.

    0 讨论(0)
  • 2020-12-07 08:57

    This will do the trick. Note the use of display() instead of print.

    with pd.option_context('display.max_rows', 5, 'display.max_columns', None): 
        display(my_df)
    

    EDIT:

    The use of display is required because pd.option_context settings only apply to display and not to print.

    0 讨论(0)
  • 2020-12-07 08:57

    A quick and dirty solution would be to convert it to a string

    print('\t'.join(data_all2.columns))
    

    would cause all of them to be printed out separated by tabs Of course, do note that with 102 names, all of them rather long, this will be a bit hard to read through

    0 讨论(0)
  • 2020-12-07 08:59

    If you just want to see all the columns you can do something of this sort as a quick fix

    cols = data_all2.columns
    

    now cols will behave as a iterative variable that can be indexed. for example

    cols[11:20]
    
    0 讨论(0)
  • 2020-12-07 09:00

    The easiest way I've found is just

    list(df.columns)
    

    Personally I wouldn't want to change the globals, it's not that often I want to see all the columns names.

    0 讨论(0)
提交回复
热议问题