head

dataframe

Returns the first n rows of a DataFrame

Syntax

head(dataframe, n?)

Parameters

dataframe (dataframe)

The DataFrame to get rows from

n (number) optional

Number of rows to return

Returns

dataframe

DataFrame containing the first n rows (default 5)

Examples

Get the first 5 rows (default behavior)
Input:
head
Output:
First 5 rows of the DataFrame
Get the first 10 rows
Input:
head(10)
Output:
First 10 rows of the DataFrame
Get just the first row
Input:
head(1)
Output:
First row of the DataFrame

The head() function returns the first n rows of a DataFrame. By default, it returns the first 5 rows if no parameter is provided.

Usage

Use head() for quick data exploration, previewing datasets, or inspecting the beginning of large files without processing the entire dataset.

Related Functions