Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Recall slicing in Python:
A slice written as ser1[start:end] with positional indices follows the normal Python rule.
It includes the element at start. It leaves out the element at end.

Step 2: Run a small example:
Take ser1 = pd.Series([10, 20, 30, 40, 50]).
The code ser1[1:3] gives the values 20 and 30.
Position 1 holds 20 and is included. Position 3 holds 40 and is excluded.
So the output has 2 elements, which is end - start.

Step 3: Check each option:
Option 1 says the end element is included. The example shows it is not, so it is wrong.
Option 2 says the end element is excluded. This matches the example, so it is correct.
Option 3 says both ends are excluded. The start element (20) is included, so it is wrong.
Option 4 says the start element is excluded. It is included, so it is wrong.

Final Answer:
The element at the end index is excluded from the output. This is option 2.
Was this answer helpful?
0
0