Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([('eagle', 'bird',    320.0),
                   ('sparrow', 'bird',     30.0),
                   ('tiger',   'mammal',   90.5),
                   ('deer', 'mammal', np.nan)],
                   columns=['name', 'class', 'max_speed'],
                   index=[0, 2, 3, 1])
df
Out[2]:
name class max_speed
0 eagle bird 320.0
2 sparrow bird 30.0
3 tiger mammal 90.5
1 deer mammal NaN

Take elements at positions 0 and 3 along the axis 0 (default):

In [3]:
df.take([0, 3])
Out[3]:
name class max_speed
0 eagle bird 320.0
1 deer mammal NaN

Take elements at indices 1 and 2 along the axis 1 (column selection):

In [4]:
df.take([1, 2], axis=1)
Out[4]:
class max_speed
0 bird 320.0
2 bird 30.0
3 mammal 90.5
1 mammal NaN

We may take elements using negative integers for positive indices, starting from the
end of the object, just like with Python lists:

In [5]:
df.take([-1, -2])
Out[5]:
name class max_speed
1 deer mammal NaN
3 tiger mammal 90.5