How to Get Specific Row in Pandas DataFrame using Index?

Pandas DataFrame – Get Specific Row using Index

To get the specific row of Pandas DataFrame using index, use DataFrame.iloc property and give the index of row in square brackets.


DataFrame.iloc returns the row as Series object.

Example 1: Get Specific Row in Pandas

In this example, we will

  • Initialize a DataFrame with some numbers.
  • Get the specific row (index = 1) using DataFrame.iloc property.

Python Program

import pandas as pd
import numpy as np

df = pd.DataFrame(
	[['a', 'b', 'c'],
	['d', 'e', 'f'],
	['g', 'h', 'i'],
	['j', 'k', 'l']])

row = df.iloc[1] #index=1 => second row


0    d
1    e
2    f
Name: 1, dtype: object

In the output: 0, 1 and 2 is the column index; and d, e, f is the row.


In this tutorial of Python Examples, we learned how to get a specific row from Pandas DataFrame using DataFrame.iloc property.