juniorPandas
What is the difference between loc and iloc?
Updated May 17, 2026
Short answer
loc uses labels; iloc uses integer positions.
Deep explanation
loc is label-based indexing, meaning it uses index names, while iloc is position-based indexing similar to arrays. loc includes the endpoint, iloc excludes it.
Real-world example
loc is used when working with labeled time series data; iloc is used for positional slicing.
Common mistakes
- Confusing label-based and position-based indexing.
Follow-up questions
- Can loc accept boolean indexing?
- Does iloc support negative indexing?