Skip to content
Related Articles

Related Articles

Get a specific row in a given Pandas DataFrame
  • Last Updated : 20 Aug, 2020

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import pandas as pd
  
# creating a DataFrame
data = {'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])

chevron_right


Output :



Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import pandas as pd
  
# creating a DataFrame
data = {'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])

chevron_right


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :