How to show all of columns name on pandas dataframe?

后端 未结 13 2013
既然无缘
既然无缘 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:39

    I had lots of duplicate column names, and once I ran

    df = df.loc[:,~df.columns.duplicated()]
    

    I was able to see the full list of columns

    Credit: https://stackoverflow.com/a/40435354/5846417

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

    You can globally set printing options. I think this should work:

    Method 1:

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

    Method 2:

    pd.options.display.max_columns = None
    pd.options.display.max_rows = None
    

    This will allow you to see all column names & rows when you are doing .head(). None of the column name will be truncated.


    If you just want to see the column names you can do:

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

    I know it is a repetition but I always end up copy pasting and modifying YOLO's answer:

    pd.set_option('display.max_columns', 500)
    pd.set_option('display.max_rows', 500)
    
    0 讨论(0)
  • 2020-12-07 08:49

    you can try this

    pd.pandas.set_option('display.max_columns', None)
    
    0 讨论(0)
  • 2020-12-07 08:51

    To get all column name you can iterate over the data_all2.columns.

    columns = data_all2.columns
    for col in columns:
        print col
    

    You will get all column names. Or you can store all column names to another list variable and then print list.

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

    Not a conventional answer, but I guess you could transpose the dataframe to look at the rows instead of the columns. I use this because I find looking at rows more 'intuitional' than looking at columns:

    data_all2.T
    

    This should let you view all the rows. This action is not permanent, it just lets you view the transposed version of the dataframe.

    If the rows are still truncated, just use print(data_all2.T) to view everything.

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