df.set_index()
df.set_index(column_name)
Moves a column to the index.
- Input:
- column_name : string
- Column name to make as the index.
- Returns:
- A new DataFrame with the
column_namecolumn as the index. - Return Type:
- DataFrame
pets = pets.set_index('ID')
pets
| Index | Species | Color | Weight | Age | Is_Cat | Owner_Comment |
|---|---|---|---|---|---|---|
| dog_001 | dog | black | 40 | 5 | False | There are no bad dogs, only bad owners. |
| cat_001 | cat | golden | 1.5 | 0.2 | True | My best birthday present ever!!! |
| cat_002 | cat | black | 15 | 9 | True | ****All you need is love and a cat.**** |
| dog_002 | dog | white | 80 | 2 | False | Love is a wet nose and a wagging tail. |
| dog_003 | dog | black | 25 | 0.5 | False | Be the person your dog thinks you are. |
| ham_001 | hamster | black | 1 | 3 | False | No, thank you! |
| ham_002 | hamster | golden | 0.25 | 0.2 | False | No, thank you! |
| cat_003 | cat | black | 10 | 0 | True | No, thank you! |
Problems or suggestions about this page? Fill out our feedback form.