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
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)
Try this:
result = data.loc[[1,10,100]]
If someone prefers to perform query for any reason, it can be done like this:
df.query("index in [1,10,100]")
From documentation of pandas.DataFrame.query:
The DataFrame.index and DataFrame.columns attributes of the DataFrame instance are placed in the query namespace by default, which allows you to treat both the index and columns of the frame as a column in the frame. The identifier index is used for the frame index; you can also use the name of the index to identify it in a query.
df.iloc[[1,10,100], :]