Search code examples
pythonpandas

Query Pandas Dataframe Index


I have a simple index on my Dataframe (integers from 0:n).

If I want row index values 1,10,100, how do I query the index to get only those rows back?

Thanks


Solution

  • In your case, the index equals to integer position. Thus you can use either .loc or .iloc.

    .loc is primarily label based...

    .iloc is primarily integer position based (from 0 to length-1 of the axis)

    See different-choices-for-indexing