How To Display Top ‘n’ Records Of DataFrame?
Table Of Contents:
- Syntax To Display Top Records Of Data Frame.
- Examples Of Displaying Top Records.
(1) Syntax:
DataFrame.head(n=5)
Description:
Return the first n rows.
- This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.
- For negative values of n, this function returns all rows except the last |n| rows, equivalent to
df[:n]
. - If n is larger than the number of rows, this function returns all rows.
Parameters:
- n: int, default 5 : Number of rows to select.
Returns:
- same type as caller: The first n rows of the caller object.
(2) Examples Of Displaying Top Records:
Example-1
import pandas as pd
path = "E:\Blogs\Pandas\Documents\Mall_Customers.csv"
customer_details = pd.read_csv(path)
customer_details
Output:
customer_details.head()
Output:
Note:
- By default, it will display top 5 records of a DataFrame.
customer_details.head(10)
Output:
Note:
- Here you can see the top 10 records of a DataFrame.