Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame take() Method

❮ DataFrame Reference


Example

Return row 5 and 10 from the DataFrame.

In this example we use a .csv file called data.csv

import pandas as pd

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

print(df.take([5, 10]))
Try it Yourself »

Definition and Usage

The take() method returns the specified rows from the DataFrame.

The take() method needs the row positions, even if the rows has named indexes.


Syntax

dataframe.take(indexes, axis, kwargs)

Parameters

The axis parameter is a keyword argument.

Parameter Value Description
indexes List Required. An array of the positions to return
axis 0
1
'index'
'columns'
Optional, default 0. The axis to select elements from
kwargs 0
1
'index'
'columns'
Optional, default 0. The axis to select elements from

Return Value

A DataFrame with the selected rows/columns.


❮ DataFrame Reference