Skip to main contentSkip to solution

Consider the given series:

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

Select the output of the following command:

seriesCapCntry[ : : -1]

Solution

✅ Correct Option: 2

The slice [ : : −1][\,:\,:\,-1] has no start or stop and a step of −1-1, so it reverses the whole series. The elements are read from the last to the first, and each index label stays with its value.

IndexValue
FranceParis
UKLondon
USAWashingtonDC
IndiaNewDelhi

Options 1 and 3: these drop India (and France), which would need a start or stop value in the slice, such as [1:4][1:4] or [1:3][1:3].

Option 4: this shows only two items, as if the slice were [−1:−3:−1][-1:-3:-1]. With no start or stop, all four items are returned.

A negative step in a pandas Series slice works just like it does in a Python list: [ : : −1][\,:\,:\,-1] always reverses.

Keyboard Shortcuts

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