How to set number of maximum rows in Pandas DataFrame?

Given a Pandas DataFrame, we have to set the number of maximum rows.
Submitted by Pranit Sharma, on May 27, 2022

In the real world, data is huge so is the dataset. While importing a dataset and converting it into DataFrame, if the number of columns or rows is large, the default printing method does not print the entire columns. It compresses the rows and columns.

In case we need to maximize the number of rows in a pandas DataFrame, we will use

pd.set_option('display.max_rows', n), where n is the maximum number of rows we want to display.

To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

Let us understand with the help of an example.

# Importing pandas package
import pandas as pd

# Importing a csv file having 
# large number of files
d = pd.read_csv('D:/Student_info.csv')

# Creating a DataFrame
df = pd.DataFrame(d)

# Display original DataFrame
print("Original DataFrame:\n",df,"\n")


Example 1: Set number of maximum rows

Here, we are having a DataFrame having 47 number of rows, suppose we want don't want all the rows to be printed and only 10 rows to save our time, we will use pd.set_option('display.max_rows', 10).

# Setting max number of rows
pd.set_option('display.max_rows', 10)

# Display Shortened DataFrame
print("Shortened DataFrame:\n",df,"\n")


Example 2: Set number of maximum rows

Python Pandas Programs »


Comments and Discussions!


Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.