pandas
  1. pandas-dataframehead

DataFrame.head() - ( Pandas DataFrame Basics )

Heading h2

Syntax

DataFrame.head(n=5)

Example

import pandas as pd

df = pd.read_csv('data.csv')
print(df.head())

Output

   Name  Age      City  Salary
0   Tom   28   Toronto   50000
1   Lee   32  New York   65000
2  Dave   25   Toronto   45000
3  Paul   29  New York   67000
4  Mark   33   Toronto   56000

Explanation

DataFrame.head(n=5) is a function in Pandas that returns the first n rows of a DataFrame. By default, it returns the first 5 rows of the DataFrame. This function is useful when you want to preview the data in a DataFrame before working with it.

Use

DataFrame.head() is used to view the first few rows of a large DataFrame. It is also useful when working with an unknown dataset, as it provides a preview of the data.

Important Points

  • DataFrame.head() is a function in Pandas that returns the first n rows of a DataFrame.
  • By default it returns the first 5 rows of a DataFrame.
  • It is useful when you want to preview the data in a DataFrame before working with it.

Summary

In conclusion, DataFrame.head() is a useful function in Pandas that helps us preview the first few rows of a large DataFrame. You can pass an integer value to head which returns the number of rows you want to see from the beginning of the DataFrame. This function is particularly useful when working with large datasets and needs to perform data analysis and manipulations.

Published on: