Skip to main contentSkip to solution

What is the output of the following python code?

import pandas as pd

seriesMnths = pd.Series([2,3,4],index=["Feb ","Mar","Apr"])

print(seriesMnths["Mar"] )

Solution

✅ Correct Option: 3

The Series pairs each label in the index with a value: "Feb " with 2, "Mar" with 3 and "Apr" with 4. Writing seriesMnths["Mar"] looks up the value stored at the label "Mar", so it prints 3.


Option 1: "Mar" is the label, not the value. Indexing with a label returns the value, not the label itself.

Option 2: 1 would be the position of "Mar" if you counted from 1. Python positions start at 0, so the position of "Mar" is 1 (not 2), but the output is the value at that position, not the position itself.

Option 4: 2 is the value for "Feb ", the first label, not for "Mar".

Keyboard Shortcuts

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