How to show all columns' names on a large pandas dataframe?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 How To Show All Columns' Names On A Large Pandas Dataframe?
00:30 Accepted Answer Score 650
01:01 Answer 2 Score 18
01:12 Answer 3 Score 80
01:37 Answer 4 Score 47
01:58 Thank you
--
Full question
https://stackoverflow.com/questions/4918...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #dataframe
#avk47
    Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 How To Show All Columns' Names On A Large Pandas Dataframe?
00:30 Accepted Answer Score 650
01:01 Answer 2 Score 18
01:12 Answer 3 Score 80
01:37 Answer 4 Score 47
01:58 Thank you
--
Full question
https://stackoverflow.com/questions/4918...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #dataframe
#avk47
ACCEPTED ANSWER
Score 650
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())
ANSWER 2
Score 80
To obtain all the column names of a DataFrame, df_data in this example, you just need to use the command df_data.columns.values.
This will show you a list with all the Column names of your Dataframe
Code:
df_data=pd.read_csv('../input/data.csv')
print(df_data.columns.values)
Output:
['PassengerId' 'Survived' 'Pclass' 'Name' 'Sex' 'Age' 'SibSp' 'Parch' 'Ticket' 'Fare' 'Cabin' 'Embarked']
ANSWER 3
Score 47
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.
ANSWER 4
Score 18
In the interactive console, it's easy to do:
data_all2.columns.tolist()
Or this within a script:
print(data_all2.columns.tolist())