CBSE Class 12 Informatics Practices Question 106 of 167

Python Pandas — I — Question 17

Back to all questions
17
Question

Question 17

What is the difference between iloc and loc with respect to a DataFrame ?

Answer
iloc methodloc method
iloc is used for integer-based indexing.loc is used for label-based indexing.
It allows to access rows and columns using integer indices, where the first row or column has an index of 0.It allows to access rows and columns using their labels (index or column names).
With iloc, the end index/position in slices is excluded when given as start:end.With loc, both the start label and end label are included when given as start:end.
The syntax is df.iloc[row_index, column_index].The syntax is df.loc[row_label, column_label].