DEV Community

chanduthedev
chanduthedev

Posted on • Edited on

34 3

Pandas Show All Rows How to display all rows from data frame using pandas

Recently I started working on machine learning using python. While doing some operation on our input data using pandas package, I came across this issue. So thought of sharing here.

Below are simple steps to load a csv file and printing data frame using python pandas framework.




import pandas
df = pandas.read_csv("data.csv")
print(df)



Enter fullscreen mode Exit fullscreen mode

This will print input data from data.csv file as below.

Alt Text

In the above image you can see total no.of rows are 29, but it displayed only FIVE rows. This is due to by default setting in the pandas library is FIVE rows only in my envrionment(some systems it will be 60 depending on the settings). Pandas property name to change this value is display.max_rows. We can change this value to display as many rows as you needed. If you want TEN rows to display, you can set display.max_rows property value to TEN as shown below.




pandas.set_option('display.max_rows', 10)
df = pandas.read_csv("data.csv")
print(df)



Enter fullscreen mode Exit fullscreen mode

And the results you can see as below which is showing 10 rows.
Alt Text

If we want to display all rows from data frame. We need to set this value as NONE or more than total rows in the data frame as below.

Code to set the property display.max_rows to None




pandas.set_option('display.max_rows', None)
df = pandas.read_csv("data.csv")
print(df)



Enter fullscreen mode Exit fullscreen mode

Code to set the property display.max_rows to just more than total rows




df = pandas.read_csv("data.csv")
pandas.set_option('display.max_rows', df.shape[0]+1)
print(df)



Enter fullscreen mode Exit fullscreen mode

Below is the screenshot displaying all the rows from the dataframe.
Alt Text

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (1)

Collapse
 
mikolajbuchwald profile image
Mikołaj Buchwald

Setting 'display.max_rows' to None:

pd.set_option('display.max_rows', None)
Enter fullscreen mode Exit fullscreen mode

will display all rows -- no limits. :)

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay