Given an Excel spreadsheet with 30 rows of data that looks like:
|------|------------|
| id | text |
|------|------------|
| 1 | apple |
| 2 | apple |
| 3 | banana |
| 4 | apple |
| 5 | orange |
| ... | ... |
| 30 | orange |
|------|------------|
I'm wondering if there's a way to do an integer-location based indexing. For example, if I wanted to return the first 3 rows starting from the 2nd row, I would use df.iloc[2:5]:
expected output:
|------|------------|
| 2 | apple |
| 3 | banana |
| 4 | apple |
|------|------------|
I would ultimately want to specify (1) the starting position and (2) the number of rows to return from the starting position, in Excel (e.g. return 10 rows starting from id=21). I've tried creating an array using INDEX but couldn't figure it out.

You need two functions for these:
MATCH will find a value in a range and return their position INDIRECT will allow you to specify a string representing a range, and it will return the values contained in that range.
Made a test like this:
My formula in K9 is:
This is how it works:
MATCH(L4;A:A;0)will find the ID position in column A. Because I said i am searching in whole column, value returned is the row number where the ID is. So if I want to find ID 2, it will return3.A3:B5. The 5 is obtained fromMATCH(L4;A:A;0)-1+L5)where i get the row number of the ID I want to find, sum up the number of rows to get, and substract 1.INDIRECT("A3:B5")is what i want and it's returned.NOTE: Depending on your Excel version, INDIRECT will auto expand to adyacent cells or not. Maybe you have to drag it manually
A video showing how it changes if i want to search different id or different number of rows:
NOTE 2: If the id is not found, MATCH will raise an error, and the formula will not work.
Check first if the ID exists in column A with COUNTIF and if true, then you do MATCH and INDIRECT. Something like this:
=IF(COUNTIF(A:A;L4)>0;INDIRECT("A"&MATCH(L4;A:A;0)&":B"&(MATCH(L4;A:A;0)-1+L5));"ID NOT FOUND")Same if number of rows returned is 0 or less.