Skip to content

Selecting a row of pandas series/dataframe by integer index

You can use the .iloc[] property to select a row by its integer index in a pandas DataFrame or Series. Note: .iloc[] selects by integer position, while .loc[] selects by label.

Select a row by its integer index in a pandas DataFrame or Series in Python

python
import pandas as pd

# Create a sample dataframe
data = {'name': ['John', 'Bob', 'Sara'], 'age': [25, 30, 35]}
df = pd.DataFrame(data)

# Select the row with index 1 (Bob)
row = df.iloc[1]
print(row)

This will output:

Output

console
name    Bob
age      30
Name: 1, dtype: object

Select multiple rows by integer indices in a pandas DataFrame or Series in Python

python
rows = df.iloc[[0, 2]]
print(rows)

This will output:

console
name  age
0  John   25
2  Sara   35

Dual-run preview — compare with live Symfony routes.