Tutorials References Exercises Videos Menu
Website Get Certified Pro NEW

Pandas DataFrame iloc Property

❮ DataFrame Reference


Example

Return the the value of the second [1] row of the first [0] column:

import pandas as pd

data = [[50, True], [40, False], [30, False]]

df = pd.DataFrame(data)

print(df.iloc[1, 0])
Try it Yourself »

Definition and Usage

The iloc property gets, or sets, the value(s) of the specified indexes.

Specify both row and column with an index.

To access more than one row, use double brackets and specify the indexes, separated by commas:

df.iloc[[0, 2]]

Specify columns by including their indexes in another list:

df.iloc[[0, 2], [0, 1]]

You can also specify a slice of the DataFrame with from and to indexes, separated by a colon:

df.iloc[0:2]

;0

Note: When slicing, the to index is excluded from the result.


Syntax

dataframe.iloc[row, column]

Parameters

Parameter Description
row Optional. A number, or numbers specifying the index of the row(s)

column Optional. A number, or numbers, specifying the index of the column(s)


Return Value

Depends on the input:

Single indexes for both row and column [1, 0] returns the content of that cell.

Single index for one row [1] returns a Pandas Series.

A list of indexes [[0, 2]] returns a Pandas DataFrame.


❮ DataFrame Reference