Question:medium

In Pandas, when extracting a portion of a Series ser1 using ser1[start:end] with positional indices start and end, which of the following statements is true?

Show Hint

Positional slicing in Pandas works as in Python: the start is included and the end is left out.
Updated On: Oct 20, 2026
  • The element at the end index is included in the output.
  • The element at the end index is excluded from the output.
  • The elements at both the start and end indices are excluded from the output.
  • The element at the start index is excluded from the output.
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Count the size of the slice:
A slice ser1[start:end] gives end - start elements.
For start = 2 and end = 5, it gives 3 elements, from positions 2, 3 and 4.
Position 5 is not among them.

Step 2: State the rule from this count:
The first position is included. The last position given is not included.
This is the half-open rule used for lists, strings and Series with positional slicing.

Step 3: Contrast with label slicing:
When labels are used with loc, such as ser1.loc['a':'c'], the end label is included.
The question asks about positional indices, so that special case does not apply.

Step 4: Eliminate the options:
Option 1 is the label-slicing behaviour, so it does not fit here.
Option 3 drops the start element, which is wrong.
Option 4 also drops the start element, which is wrong.
Option 2 fits the rule.

Final Answer:
The end index is excluded, which is option 2.
Was this answer helpful?
0