KnowledgeBoat Logo
|

Informatics Practices

Identify the correct option to select first four rows and second to fourth columns from a DataFrame 'Data':

  1. display(Data.iloc[1 : 4, 2 : 4])
  2. display(Data.iloc[1 : 5, 2 ; 5])
  3. print(Data.iloc[0 : 4, 1 : 4])
  4. print(Data.iloc[1 : 4, 2 : 4])

Python Pandas

1 Like

Answer

print(Data.iloc[0 : 4, 1 : 4])

Reason — To display subset from dataframe using row and column numeric index/position, iloc is used with syntax <DF object>.iloc[<start row index>:<end row index>, <start col index>:<end col index>]. Therefore, according to this syntax, print(Data.iloc[0 : 4, 1 : 4]) is correct statement to display first four rows and second to fourth columns from a DataFrame Data.

Answered By

1 Like


Related Questions