Get a specific row in a given Pandas DataFrame
In the Pandas DataFrame we can find the specified row value with the using function iloc(). In this function we pass the row number as parameter.
pandas.DataFrame.iloc[]
Syntax : pandas.DataFrame.iloc[]
Parameters :
- Index Position : Index position of rows in integer or list of integer.
Return type : Data frame or Series depending on parameters
Example 1 :
# importing the moduleimport pandas as pd # creating a DataFramedata = {'1' : ['g', 'e', 'e'], '2' : ['k', 's', 'f'], '3' : ['o', 'r', 'g'], '4' : ['e', 'e', 'k']}df = pd.DataFrame(data)print("Original DataFrame")display(df) print("Value of row 1")display(df.iloc[1]) |
Output :

Example 2:
# importing the moduleimport pandas as pd # creating a DataFramedata = {'Name' : ['Simon', 'Marsh', 'Gaurav', 'Alex', 'Selena'], 'Maths' : [8, 5, 6, 9, 7], 'Science' : [7, 9, 5, 4, 7], 'English' : [7, 4, 7, 6, 8]} df = pd.DataFrame(data)print("Original DataFrame")display(df) print("Value of row 3 (Alex)")display(df.iloc[3]) |
Output :




