Skip to main content

Python Pandas Series: head() function

In Pandas head() function is used to explore data structures or data of a series without producing all of it from the top. It is a very convenient easy and quick method to try with data without actually dumping into it.

It is used to return top n rows of the series or dataframe. If we do not define n then it returns top 5 rows by default.

Syntax

Series.head(n=5)

n: The number of rows to be returned. By default n=5

Return: Series with top n rows.

Example

import pandas as pd

series_0=pd.Series([i for i in range(50)])

When n = 10

series_0.head(10)

Output:

0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: int64

When n is not given

series_0.head()

Output:

0    0
1    1
2    2
3    3
4    4
dtype: int64
Submitted by devanshi.srivastava on November 3, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.