Pandas loc vs. ilocThe Pandas offers .loc[] and .iloc[] methods for data slicing. Data Slicing generally refers to inspect your data sets. These two methods belong to the index selection method that is used to set an identifier for each row of the data set. The indexing can take specific labels, and these labels can either be an integer or any other value specified by the user. The .loc[] method is used to retrieve the group of rows and columns by labels or a boolean array present in the DataFrame. It takes only index labels, and if it exists in the caller DataFrame, it returns the rows, columns, or DataFrame. It is a label-based method but may be used with the boolean array. Whereas, the .iloc[] method is used when the index label of the DataFrame is other than numeric series of 0,1,2,....,n, or in the case when the user does not know the index label. There are some differences between the above methods, which are given below:
Next TopicPandas Cheat Sheet
|