In this section, we will explore how to set an index and use it for data analysis in pandas. We will learn how to set an index on the DataFrame after reading in the data, as well as while reading in data. We'll also see how to use this index for data selection.
As always, we start by importing the pandas module into our Jupyter notebook:
import pandas as pd
We then read in our dataset:
data = pd.read_csv('data-titanic.csv')
The following is how our default index looks like right now, which is a numeric index starting from 0:
Let's set it to a column of our choice. Here, we use the set_index method ...