Specifying a column as an index

By default, read_csv assigns a default numeric index starting with zero while reading the data. However, you can change this behavior by passing the column name to the index column option. pandas will then set the index to this column, as shown in the following code:

df = pd.read_csv('IMDB.csv', encoding = "ISO-8859-1", index_col='Title')df.head()

Here, we passed a movie title as the index name. Now the index name is Title, instead of a default numeric index, as shown in the following screenshot:


Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.