How to widen output display to see more columns in Pandas dataframe?

In Python, if there are many more number of columns in the dataframe, then not all the columns will be shown in the output display. So, let’s see how to widen output display to see more columns.

Method 1: Using pandas.set_option() function.

This function is used to set the value of a specified option.

Syntax: pandas.set_option(pat, value)

Returns: None



Example:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing numpy library 
import numpy as np
  
# importing pandas library
import pandas as pd
  
# define a dataframe of
# 2 rows and 100 columns
# with random entries
df = pd.DataFrame(np.random.random(200).reshape(2, 100))
  
# show the dataframe
df

chevron_right


Output:

dataframe

To print the above output in a wider format using pandas.set_option() function.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# using pd.set_option()
# to widen the output 
# display
pd.set_option('display.max_columns', 100)
  
# show the dataframe
df

chevron_right


Output:

Wider column shows



Method 2: Using pd.options.display.max_columns attribute.

This attribute is used to set the no. of columns to show in the display of the pandas dataframe.

Example:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing numpy library
import numpy as np
  
# importing pandas library
import pandas as pd
  
# define a dataframe of
# 15 rows and 200 columns
# with random entries
df = pd.DataFrame(np.random.randint(0, 100
                                    size =(15, 200)))
  
# show the dataframe
df

chevron_right


Output:

Default Column Frame

To print the above output in a wider format using pd.options.display.max_columns attribute.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# using an alternative
# way to use 
# pd.set_option() method
# to widen the output 
# display
pd.options.display.max_columns = 200
  
# show the dataframe
df

chevron_right


Output:

Wider Column Frame

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.