DEV Community

chanduthedev
chanduthedev

Posted on • Edited on

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

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. :)