Skip to main contentSkip to solution

What will be the output of the following commands?

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

seriesCapCntry[1:3]

Solution

✅ Correct Option: 3

Slicing with integer positions, as in seriesCapCntry[1:3], works like list slicing. It includes the start position and excludes the end position, so it returns positions 1 and 2.

Position 1 is USA with WashingtonDC, and position 2 is UK with London. The output is:

USA    WashingtonDC
UK           London
dtype: object

Options 1, 2 and 4: they include NewDelhi (India), which sits at position 0, outside the slice.

Slicing by label, such as seriesCapCntry['USA':'UK'], includes the end label, but a positional slice like [1:3] excludes the end.

Keyboard Shortcuts

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