
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Display specific number of rows from a DataFrame
To display specific number of rows from a DataFrame, use the head() function. Set the parameter to be the number of row records to be fetched. For example, for 10 rows, mention −
dataFrame.head(10)
At first, let us import the required library with an alias −
import pandas as pd
Our CSV is on the Desktop as shown in the below path −
C:\Users\amit_\Desktop\CarRecords.csv
Let us read the CSV file and create Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")
Return specific number of rows i.e. in this case, we are returning top 5 row records −
dataFrame.head(5)
Example
Following is the code
import pandas as pd # reading csv file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") print("DataFrame...\n",dataFrame) # returns top 5 row records print("DataFrame with specific number of rows...\n",dataFrame.head(5))
Output
This will produce the following output
DataFrame... Car Place UnitsSold 0 Audi Bangalore 80 1 Porsche Mumbai 110 2 RollsRoyce Pune 100 3 BMW Delhi 95 4 Mercedes Hyderabad 80 5 Lamborghini Chandigarh 80 6 Audi Mumbai 100 7 Mercedes Pune 120 8 Lamborghini Delhi 100 DataFrame with specific number of rows ... Car Place UnitsSold 0 Audi Bangalore 80 1 Porsche Mumbai 110 2 RollsRoyce Pune 100 3 BMW Delhi 95 4 Mercedes Hyderabad 80
- Related Articles
- Python - Drop specific rows from multiindex Pandas Dataframe
- Python - Sum only specific rows of a Pandas Dataframe
- Python Pandas - Select a subset of rows from a dataframe
- Python - Ranking Rows of Pandas DataFrame
- Python Pandas - How to select multiple rows from a DataFrame
- Python - How to drop the null rows from a Pandas DataFrame
- Python - Summing all the rows of a Pandas Dataframe
- Python Pandas - Filtering few rows from a DataFrame on the basis of sum
- Compare specific Timestamps for a Pandas DataFrame – Python
- Python Pandas - How to select rows from a DataFrame by integer location
- Python Pandas - How to append rows to a DataFrame
- Python Pandas - How to select rows from a DataFrame by passing row label
- Python - Search DataFrame for a specific value with pandas
- Use a list of values to select rows from a Pandas DataFrame
- Select rows from a Pandas DataFrame based on column values

Advertisements