Vicky Zhang
Vicky Zhang

Reputation: 529

pandas: how to merge multiple indexes together?

I have two levels of index, and I want to merge them into one level of index. I looked at methods such as reset_index and reindex, but they don't seem to be what I need. Another way I can think of is adding a new column containing the merged indexes, set that column as the new index using pivot_table, and delete the old indexes. But I'm wondering is there a more elegant way to do this. Any input is welcomed. Thank you so much!

Upvotes: 0

Views: 1448

Answers (1)

JoeCondron
JoeCondron

Reputation: 8906

Doing

df.index = df.index.values

will give you tuples in a single level if that's what you mean by 'merge'.

Upvotes: 1

Related Questions