How come the result of the .iloc is not a list?

Question

How come the result of the .iloc is not a list? Why does it show a series?

Answer

When using iloc in Pandas, it will return a specified row, but in the form of a Series.

The left column in the result is composed of indexes which are the column names from the dataframe. And the right column is composed of the values for each column in the row of data.

This is a helpful feature in Pandas because it displays all the information about the columns and values of a row in a clear way.

4 Likes

So basically, it takes the data from the list and creates a different series?

It creates a series from the table. The result set is called the Series, which is a form of the table that you choose to create.

The way I think of iloc() for a single row is taking that row of data from the data frame and transposing it into a column (i.e., series). Not sure how accurate that way of looking at it is, but helps me visualize it.

3 Likes

That’s exactly what I think too. Resulting data is a series, but transposed compared to the original.