3 ms·
Thanks 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 po
by jalammar 8y ago
Thanks 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?