What will be the output of the following commands?
seriesCapCntry = pd.Series(['NewDelhi', 'WashingtonDC', 'London', 'Paris'], index=['India', 'USA', 'UK', 'France'])
seriesCapCntry[1:3]
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
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.
Related questions:
2026: 24 May Shift 1
2026: 21 May Shift 1
2026: 13 May Shift 2