Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * [ Essential basic functionality ](basics.html)
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * Indexing and selecting data 
  * [ MultiIndex / advanced indexing ](advanced.html)
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * [ Working with text data ](text.html)
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * [ Nullable Boolean data type ](boolean.html)
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * [ Time deltas ](timedeltas.html)
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * Indexing... 

#  Indexing and selecting data  #

The axis labeling information in pandas objects serves many purposes:

  * Identifies data (i.e. provides _metadata_ ) using known indicators, important for analysis, visualization, and interactive console display. 

  * Enables automatic and explicit data alignment. 

  * Allows intuitive getting and setting of subsets of the data set. 

In this section, we will focus on the final point: namely, how to slice, dice,
and generally get and set subsets of pandas objects. The primary focus will be
on Series and DataFrame as they have received more development attention in
this area.

Note

The Python and NumPy indexing operators ` []  ` and attribute operator ` .  `
provide quick and easy access to pandas data structures across a wide range of
use cases. This makes interactive work intuitive, as thereâs little new to
learn if you already know how to deal with Python dictionaries and NumPy
arrays. However, since the type of the data to be accessed isnât known in
advance, directly using standard operators has some optimization limits. For
production code, we recommended that you take advantage of the optimized
pandas data access methods exposed in this chapter.

Warning

Whether a copy or a reference is returned for a setting operation, may depend
on the context. This is sometimes called ` chained  assignment  ` and should
be avoided. See  Returning a View versus Copy  .

See the [ MultiIndex / Advanced Indexing  ](advanced.html#advanced) for `
MultiIndex  ` and more advanced indexing documentation.

See the [ cookbook  ](cookbook.html#cook