Difference of .loc and shortcut when slicing rows

Why does the second number have to be one lower when slicing rows with .loc?

Hey there!

.loc[] has inclusive slicing behavior — this means that you slice up to, and including, the ending index.

On the other hand, normal slicing behavior in Python slices up to but not including the ending index.

Is there any reasoning behind this design decision?
Seems incoherent and unnecessarily complicated to me.

Another one I have caught:
The parameter to exclude NaN in Series.value_counts() is dropna.
Why on earth dropna and not dropnan? :expressionless:

Might be a better question for the pandas folks haha. But, as with any other language, these are just idiosyncrasies you’ll just need to get used to :man_shrugging:t4:

1 Like

Yes, agreed. Just wanted to have a little rant.

I looked through their GitHub Issues and the slicing behaviour is not going to change. It had been brought up already.