Issue
If I have a data frame df
and want to select multiple rows.
Using .iloc
I can do df.iloc[1:8]
, but doing the same using .loc
requires either doing
df.loc[1:8]
or
df.loc[[1,2,3,4,5,6,7,]]
I am curious to know about the reasoning behind the double brackets for the. loc
Solution
The .loc[]
method is a label based method that means it takes names or labels of the index when taking the slices, whereas .iloc[]
method is based on the index's position.
To answer your question: the arguments of .loc
are
- row label
- list of row labels : (double brackets) means that you can pass the list of rows when you need to work with specific set of rows.
example. you will have row indices when you use cross validation techniques.
Answered By - Sauron
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.