Can someone explain how these two methods of slicing are different?
I've I've seen the docs,the docs
and I've seen previous similar questions (these1, answers2), but I still find myself unable to understand how the threethey are different. To me, they seem interchangeable in large part, because they are at the lower levels of slicing.
For example, say we want to get the first five rows of a DataFrame
. How is it that these two work?
df.loc[:5]
df.iloc[:5]
df.loc[:5]
df.iloc[:5]
Can someone present three cases where the distinction in uses are clearer?
Once upon a time, I also wanted to know how these two functions differdiffered from df.ix[:5]
but ix
has been removed from pandas 1.0, so I don't care anymore.