Pandas DataFrame: head() function - w3resource (2024)

DataFrame - head() function

The head() function is used to get 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.

Syntax:

DataFrame.head(self, n=5)

Parameters:

NameDescriptionType/Default Value Required / Optional
nNumber of rows to select.int
Default Value: 5
Required

Returns: obj_head : same type as caller
The first n rows of the caller object.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - notna() function
Next: DataFrame - at() function



Pandas DataFrame: head() function - w3resource (2024)
Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6183

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.