What is the leftmost column when we print a dataframe in Pandas?

Question

When we print out a dataframe, what is the leftmost column? This is the column which shows numbers like 0, 1, 2, ... and which has no column title.

Answer

The leftmost column shown when we print out a dataframe is known as the “index”, or “row labels”, of a dataframe.

By default, every dataframe that you create or load from a file will have this column of values which starts from 0 and increases sequentially for each row. These values are essentially like the identification for each row, as each value should be unique per row.

To see the values of this column, you can access a dataframe’s index property like so,

df.index

We can use these values to select a specific row using the loc method. For example, if a row had an index value of 20, we can select it using

df.loc[20]

One thing to note later on in the lesson is that loc is different from iloc, which we use to select rows by location in the table, not by the value in the index column.

5 Likes

Thanx @jephos249 for the answer. I really want to become “Data Scientist”.

11 Likes