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
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
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())
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)
you can try this
pd.pandas.set_option('display.max_columns', None)
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.
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.