← All notes

pandas selection with loc and iloc

Answer: pandas supports three types of multi-axis indexing. .loc is primarily label based, but may also be used with a boolean array, and .loc will raise KeyError when the items are not found. (S1)

Rows, then columns

Label versus position

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: pandas docs, Indexing and selecting data — pandas 3.1.1 documentation, BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE); pandas docs, How do I select a subset of a DataFrame? — pandas 3.1.1 documentation, BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE).

Cite this

Permanent ID: iil:note:ha0s3t0k

iinventedlight. 2026. "pandas selection with loc and iloc." iinventedlight Library, iil:note:ha0s3t0k, version of 2026-11-04. https://iinventedlight.com/library/notes/pandas-indexing-loc-iloc/. License: CC-BY-4.0.

@misc{iil_note_ha0s3t0k,
  author = {{iinventedlight}},
  title = {{pandas selection with loc and iloc}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/pandas-indexing-loc-iloc/},
  note = {Permanent ID iil:note:ha0s3t0k. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/pandas-indexing-loc-iloc.md.