Home » Pandas DataFrame.head()

Pandas DataFrame.head()

by Online Tutorials Library

Pandas DataFrame.head()

The head() returns the first n rows for the object based on position. If your object has the right type of data in it, it is useful for quick testing. This method is used for returning top n (by default value 5) rows of a data frame or series.

Syntax

Parameters

n: It refers to an integer value that returns the number of rows.

Return

It returns the DataFrame with top n rows.

Example1

Output

       language  0        C  1       C++  2       Python  

Example 2

We have a csv file “aa.csv” that have the following dataset.

By using the head() in the below example, we showed only top 2 rows from the dataset.

       Name          Hire Date      Salary      Leaves Remaining  0     John Idle        03/15/14     50000.0        10  1     Smith Gilliam    06/01/15     65000.0        8  

Next TopicDataFrame.hist()

You may also like