2

Is there any way to retrieve the multi-index value based on the row number? Like can I use .iloc[0] to retrieve somehow the value of the multi-index in an array form?

For example I have a multi-index [month, day, hour]. Can I use iloc[numRow] and get for example (1,1,1) being the multi-index values month 1, day 1 and hour 1?

df.iloc[numRow].get_index() does not work since it becomes a series and then it returns the column names as the index, but I really want the value of the multi-index of the row.

1 Answer 1

1

How about:

df.index[numRow]

(You can always use integer-based slicing on Index objects...)

Sign up to request clarification or add additional context in comments.

2 Comments

OMG...I feel so stupid now...thanks for the answer, I'll mark it as correct.
Glad it helped. I remember having this particular epiphany. Useful stuff! One other note: the to_series method (called on an index or multiindex object) is also quite useful. So while df.index.apply blows chunks, df.index.to_series().apply works nicely, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.