3 ms·
Note to author: > We can select one or multiple rows using their numbers (inclusive of both bounding row numbers): > df[1:3] That will slice beginning from t
by happy-go-lucky 8y ago
Note to author:
> We can select one or multiple rows using their numbers (inclusive of both bounding row numbers):
> df[1:3]
That will slice beginning from the row with integer location 1 up to 3, exclusive of the last element. So, just two rows, not three as shown.
- jalammar 8y agoThanks for the heads up! Indeed it's df.loc[1:3] that would return three rows, not straight-up df[1:3] which indeed returns two rows. Edit: Corrected in the post. Thanks again!
- yufeng66 8y agoBut why design it that way? Seems to be a sure way to confuse new user.
- EForEndeavour 8y agoI'd say that's because df[start:stop] mimics python's builtin list slicing, which includes start but excludes end, so this dictates the behaviour of indexing without .loc. By contrast, df.loc[start:stop] is a label-based indexer, and labels can be anything (integers, strings, datetimes, categories, etc.), so it doesn't always make sense to exclude the right endpoint of the interval.
- happy-go-lucky 8y ago(^^)b
- rapfaria 8y agoGenuine question, did you run the original before publishing it on the website?