user2261062
user2261062

Reputation:

No horizontal scrollbar when printing dataframe in jupyter

When printing a pandas dataframe in jupyter, no horizontal scroll is created, instead columns that don't fit are printed after the columns that fit.

Toy example:

d = {'long_column_name1': [1, 2,3,4,5,6,7,8,9], 
     'long_column_name2': [1, 2,3,4,5,6,7,8,9], 
     'long_column_name3': [1, 2,3,4,5,6,7,8,9], 
     'long_column_name4': [1, 2,3,4,5,6,7,8,9],
     'long_column_name5': [1, 2,3,4,5,6,7,8,9], 
     'long_column_name6': [1, 2,3,4,5,6,7,8,9],
     'long_column_name7': [1, 2,3,4,5,6,7,8,9], 
     'long_column_name8': [1, 2,3,4,5,6,7,8,9]}
df = pd.DataFrame(data=d)
print(df)

enter image description here

In this case there are only 9 rows, and 8 columns, which is still readable, but having more rows and columns will make it really hard to read.

Is there a way that all columns are printed horizontally, adding an horizontal scrollbar if needed?

Upvotes: 4

Views: 9775

Answers (2)

InLaw
InLaw

Reputation: 2697

(in Jupyter without print() )

change the pandas option settings

like:

pd.set_option('display.max_columns', 70)

for printing all (string-)content in a cell:

pd.set_option('display.max_colwidth', None) # for pandas >= 1.x

or temporarily (in with statement) :

with pd.option_context("display.max_rows", 8, "display.max_columns", 90):
     print(pd.get_option("display.max_rows")
     print(pd.get_option("display.max_columns"))
# back in general setting
print(pd.get_option("display.max_rows"))

Upvotes: 1

Tox
Tox

Reputation: 854

You can try df instead of print(df). Which makes it scrollable.

And if you want the columns to be printed horizontal you could use df.transpose().

Upvotes: 4

Related Questions