Pandas tricks — pd.set_option()

Displaying dataframe contents while doing EDA is the most common thing. df.head() being the most handy method available for the same.

Alternatively, just run df on the notebook to display all of the content of the dataframe.

As can see, that there are 90 rows and 3 columns in the dataframe. But running df command shows only few rows and not all.

Usually we work on large datasets, and hence there is no real need to display whole of the dataframe on the console output. But sometimes, we work on smaller datasets like this one, and need arises to see the whole set of records as the output for some visual analysis.

Lets see, if df.head(90) can come to the rescue ?

Seems no.

Then we need to change some default setting of the pandas.

pd provide whole range of settings through set_options api, that can be manipulated based on your needs.

If we want to see all of the records of the dataframe in the console output -

pd.set_option(“display.max_rows”, None)

In this case, we have only 3 columns, but if there are many columns which is not displayed all at once, then we can use -

Now, if you see “COMMENT” column, it has a large text, which is not displayed in entirety.

Thank you !

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Shekhar Khandelwal
Shekhar Khandelwal

Written by Shekhar Khandelwal

Data Scientist with a majors in Computer Vision. Love to blog and share the knowledge with the data community.

No responses yet