pby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.take  #

DataFrame.  take  (  _ indices  _ , _ axis  =  0  _ , _ **  kwargs  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/generic.py#L4027-L4140) #

    

Return the elements in the given _positional_ indices along an axis.

This means that we are not indexing according to actual values in the index
attribute of the object. We are indexing according to the actual position of
the element in the object.

Parameters  :

    

**indices** array-like

    

An array of ints indicating which positions to take.

**axis** {0 or âindexâ, 1 or âcolumnsâ, None}, default 0

    

The axis on which to select elements. ` 0  ` means that we are selecting rows,
` 1  ` means that we are selecting columns. For  Series  this parameter is
unused and defaults to 0.

****kwargs**

    

For compatibility with ` numpy.take()  ` . Has no effect on the output.

Returns  :

    

same type as caller

    

An array-like containing the elements taken from the object.

See also

[ ` DataFrame.loc  ` ](pandas.DataFrame.loc.html#pandas.DataFrame.loc
"pandas.DataFrame.loc")

    

Select a subset of a DataFrame by labels.

[ ` DataFrame.iloc  ` ](pandas.DataFrame.iloc.html#pandas.DataFrame.iloc
"pandas.DataFrame.iloc")

    

Select a subset of a DataFrame by positions.

[ ` numpy.take  `
](https://numpy.org/doc/stable/reference/generated/numpy.take.html#numpy.take
"\(in NumPy v1.26\)")

    

Take elements from an array along an axis.

Examples

    
    
    >>> df = pd.DataFrame([('falcon', 'bird', 389.0),
    ...                    ('parrot', 'bird', 24.0),
    ...                    ('lion', 'mammal', 80.5),
    ...                    ('monkey', 'mammal', np.nan)],
    ...                   columns=['name', 'class', 'max_speed'],
    ...                   index=[0, 2, 3, 1])
    >>> df
         name   class  max_speed
    0  falcon    bird      389.0
    2  parrot    bird       24.0
    3    lion  mammal       80.5
    1  monkey  mammal        NaN
    

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

Note how the actual indices selected (0 and 1) do not correspond to our
selected indices 0 and 3. Thatâs because we are selecting the 0th and 3rd
rows, not rows whose indices equal 0 and 3.

    
    
    >>> df.take([0, 3])
         name   class  max_speed
    0  falcon    bird      389.0
    1  monkey  mammal        NaN
    

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

    
    
    >>> df.take([1, 2], axis=1)
        class  max_speed
    0    bird      389.0
    2    bird       24.0
    3  mammal       80.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.

    
    
    >>> df.take([-1, -2])
         name   class  max_speed
    1  monkey  mammal        NaN
    3    lion  mammal       80.5
    

[ __ previous  pandas.DataFrame.set_index  ](pandas.DataFrame.set_index.html
"previous page") [ next  pandas.DataFrame.truncate  __
](pandas.DataFrame.truncate.html "next page")

__ On this page

  * ` DataFrame.take()  `

[ __ Show Source ](../../_sources/reference/api/pandas.DataFrame.take.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.