Locked lesson.
About this lesson
There are times when you may need to reset your index within a data frame, so we'll explain how that works in this video.
Exercise files
Download this lesson’s related exercise files.
Changing Indexes.docx57 KB Changing Indexes - Solution.docx
55.5 KB
Quick reference
Changing Indexes
We can reset our index to its original numeric values, and we can create a completely different index with different labels.
When to use
Do this whenever you need to reset your index to numbers, or create a new labelled index.
Instructions
To reset an index to its original numerical values:
my_df.reset_index(inplace=True)
To create a new column and set it as the index:
my_df['New'] = ["E", "F", "G", "H"]
my_df.set_index('New', inplace=True)
Hints & tips
- Reset Index: my_df.reset_index(inplace=True)
- Create New Column: my_df['New'] = ["E", "F", "G", "H"]
- Set New Column as Index: my_df.set_index('New', inplace=True)
Lesson notes are only available for subscribers.