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
In the interactive console, it's easy to do:
data_all2.columns.tolist()
Or this within a script:
print(data_all2.columns.tolist())
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.
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
.
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
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]
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.