Koskamo

Indexing and selecting data

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Use .loc for label-based indexing and .iloc for integer position-based access, as direct operator usage limits optimization in production code. .loc raises KeyError for missing items, supporting labels, label slices (inclusive endpoints), boolean arrays, callables, and tuples. Treat numeric labels like 5 strictly as index labels, not positions. .iloc raises IndexError for out-of-bounds positions but permits out-of-bounds slices. It accepts integers, integer lists, integer slices, boolean arrays, callables, and tuples. Both .loc and .iloc accept callable indexers. Note that destructuring tuple keys into row and column indexes happens before callable application, preventing callables from returning tuples for multi-axis indexing. Omitted axes default to the null slice; for example, p.loc['a'] is equivalent to p.loc['a', :]. For advanced strategies, consult MultiIndex and cookbook documentation. Scope: pandas. Reviewed October 4, 2026.

Source and provenance

Original source
pandas.pydata.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.