head() method

Returns a specified number of rows from the top of a dataframe.

Syntax

dataframe_name|dataframe_name["column_name"].head(number = number_of_rows)

Parameters

Name Description

number = number_of_rows

optional

The number of rows to return, or the number of values if you specify a column.

If you specify a negative number, all rows in the dataframe are returned except for the bottom -n rows.

If you omit the parameter, the top 5 rows are returned by default.

Specifying number = is optional.

Returns

HCL dataframe.

Examples

Return the first 5 rows from the top of a dataframe

accounts_receivable.head()

Return the first 25 rows from the top of a dataframe

accounts_receivable.head(25)

Return all rows in a dataframe except for the last one

accounts_receivable.head(-1)

Return the first 5 values from the top of a column

The values are returned from the Customer Number column as a series rather than a dataframe.

accounts_receivable["Customer Number"].head()

Remarks

HCL does not currently support the tail() method for returning rows from the bottom of a dataframe. However, you can convert the HCL dataframe to a Pandas dataframe and use tail() if you want to return bottom rows.

Return the last 10 rows from the bottom of a dataframe

import pandas as pd
accounts_receivable_pd = accounts_receivable.to_pandas()
accounts_receivable_pd.tail(10)