Informatics Practices

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

Python Pandas

7 Likes

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].

Answered By

4 Likes


Related Questions