Skip to main contentSkip to solution

df = pd. Series(['London', 'Paris', 'NewDelhi', 'Moscow'], index = ['UK', 'France', 'India', 'Russia'])

Which of the following would reverse the order of the series?

Solution

✅ Correct Option: 3

The slice df[::-1] uses a step of -1 with the start and stop left blank. This walks through the Series from the last element to the first, giving Russia (Moscow), India (NewDelhi), France (Paris), UK (London). The index labels reverse along with the values.


Option 1: df[:-1] keeps the order and only drops the last element.

Option 2: df[-1:-3] has a positive step, so it goes from the end towards the end, and the result is an empty Series.

Option 4: df[3::1] starts at position 3 and moves forward, returning only the last element (Moscow).

In slicing, a negative step reverses the direction, so [::-1] is the standard way to reverse a Series, list or string.

Keyboard Shortcuts

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