James Haskell
James Haskell

Reputation: 2025

Index column names

How can I get a list of the names of columns in an index?

Example:

df1 = pd.DataFrame(np.arange(20.).reshape((4,5)), columns=list('abcde'))
df1 = df1.set_index(['a','b'], drop=False) 
        a   b   c   d   e
a  b
0  1    0   1   2   3   4
5  6    5   6   7   8   9
10 11  10  11  12  13  14
15 16  15  16  17  18  19

Is there a way to query df1 to get the index columns: "['a','b']"?

Upvotes: 0

Views: 912

Answers (1)

acushner
acushner

Reputation: 9946

it's actually pretty straightforward:

df1.index.names

Upvotes: 1

Related Questions