From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Modifying a MultiIndex

Modifying a MultiIndex

- [Instructor] Okay, so in the case that we create a multi-index DataFrame or get passed one by a colleague and want to modify those multi-indices, there's a few things that we can do. One thing that we can do is just reset the index. This will move the index levels back to being DataFrame columns. And we can do so using the reset index method. So the reset index method is a lifesaver. We can push our family and store number, which were stored in our index, back into being columns just by using the reset index method. This is probably the most common operation I perform on multi-index DataFrames. We can also swap the levels in our multi-index. This will change the hierarchy for the index levels. So for whatever reason we want to swap automotive and store number, we can do so with swap level. So if we just have two levels of a multi-index, swap level will swap the two levels. So now when we started, our family was our outer layer of our index, and now store number is the outer layer of…

Contents