ERed ERed - 5 months ago 26
Python Question

get multiindex value based on row number in Pandas

Is there any way to retieve the multiindex value based on the number of row?
Like can I use

.iloc[0]
to retrieve somehow the value of the multiindex in an array form?

For example I have a multiindex [month, day, hour]. Can i use iloc[numRow] and get for exmple (1,1,1) being the multiindex 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 multiindex of the row.

Answer

How about:

df.index[numRow]

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