12
df = pd.DataFrame({'a':[2,3,5], 'b':[1,2,3], 'c':[12,13,14]})
df.set_index(['a','b'], inplace=True)
display(df)
s = df.iloc[1]
# How to get 'a' and 'b' value from s? 

It is so annoying that ones columns become indices we cannot simply use df['colname'] to fetch values.

Does it encourage we use set_index(drop=False)?

2 Answers 2

20

When I print s I get

In [8]: s = df.iloc[1]

In [9]: s
Out[9]:  
c    13
Name: (3, 2), dtype: int64

which has a and b in the name part, which you can access with:

s.name

Something else that you can do is

df.index.values

and specifically for your iloc[1]

df.index.values[1]

Does this help? Other than this I am not sure what you are looking for.

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

Comments

1

if you want to get "a" and "b"

df.index.names

gives: FrozenList(['a', 'b'])

Comments

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.