Skip to main contentSkip to solution

What will be the output of the following code?

seriesCapCntry = pd.Series(['NewDelhi', 'WashingtonDC', 'London', 'Paris'], index=['India', 'USA', 'UK', 'France'])

seriesCapCntry[1:3]

Solution

✅ Correct Option: 1

Integer slicing on a Series is positional, like a Python list: [1:3][1:3] takes positions 1 and 2, and stops before position 3. Position 0 is India, so the slice returns USA and UK together with their index labels.

USA    WashingtonDC
UK     London
dtype: object

Slicing with labels works differently: seriesCapCntry['USA':'UK'] gives the same result here, but the end label is included.


Option 2: a Series always prints its index labels along with the values, so the labels cannot be left out.

Option 3: this would need the end position to be included, but with [1:3][1:3] position 3 (France) is excluded.

Option 4: this starts from position 0 (India), but the slice starts at position 1.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question