How can I display all columns of a Pandas DataFrame? 2

How can I display all columns of a Pandas DataFrame?

To display all columns of a Pandas DataFrame, use the “.columns” attribute, which returns a list of all the columns in the DataFrame. This can be further combined with the “.head()” or “.tail()” methods to display the first or last few rows of the DataFrame with all columns included. Alternatively, the “.info()” method can be used to display a summary of the DataFrame, including all columns and their data type. Additionally, the “.describe()” method can be used to show summary statistics for all numerical columns in the DataFrame. Overall, these methods provide easy and effective ways to display all columns of a Pandas DataFrame.

Show All Columns of a Pandas DataFrame


By default, Jupyter notebooks only displays 20 columns of a pandas DataFrame.

You can easily force the notebook to show all columns by using the following syntax:

pd.set_option('max_columns', None)

You can also use the following syntax to display all of the column names in the DataFrame:

print(df.columns.tolist())

Lastly, you can reset the default settings in a Jupyter notebook to only show 20 columns by using the following syntax:

pd.reset_option('max_columns')

The following example shows how to use these functions in practice.

Example: Show All Columns in Pandas DataFrame

Suppose we create a pandas DataFrame with 5 rows and 30 columns.

If we attempt to display the DataFrame in a Jupyter notebook, only 20 total columns will be shown:

import pandas as pd
import numpy as np

#create dataFrame with 5 rows and 30 columns
df = pd.DataFrame(index=np.arange(5), columns=np.arange(30))

#view dataFrame
df

To display all of the columns, we can use the following syntax:

#specify that all columns should be shown
pd.set_option('max_columns', None)

#view DataFrame
df

Notice that all 30 columns are now shown in the notebook.

print(df.columns.tolist())

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29]

To reset the default settings and only display a max of 20 columns, we can use the following syntax:

pd.reset_option('max_columns')

How to Show All Rows  in Pandas DataFrame

If you’d like to show every row in a pandas DataFrame, you can use the following syntax:

pd.set_option('max_rows', None) 

You can also specify a max number of rows to display in a pandas DataFrame. For example, you could specify that only a max of 10 rows should be shown:

pd.set_option('max_rows', 10) 

The following tutorials explain how to perform other common operations on pandas DataFrames:

Cite this article

stats writer (2024). How can I display all columns of a Pandas DataFrame?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-display-all-columns-of-a-pandas-dataframe/

stats writer. "How can I display all columns of a Pandas DataFrame?." PSYCHOLOGICAL SCALES, 3 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-display-all-columns-of-a-pandas-dataframe/.

stats writer. "How can I display all columns of a Pandas DataFrame?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-display-all-columns-of-a-pandas-dataframe/.

stats writer (2024) 'How can I display all columns of a Pandas DataFrame?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-display-all-columns-of-a-pandas-dataframe/.

[1] stats writer, "How can I display all columns of a Pandas DataFrame?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.

stats writer. How can I display all columns of a Pandas DataFrame?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top