Skip to main contentSkip to solution

What will be the output of the following Python code?

import pandas as pd

dict1 = {'India': 'NewDelhi', 'UK': 'London', ‘Japan’: 'Tokyo'}

series8 = pd.Series(dict1)

print(series8)

Solution

✅ Correct Option: 1

When a dictionary is passed to pd.Series(), the keys become the index (labels) and the values become the data. So the index is India, UK, Japan, and the values are NewDelhi, London, Tokyo, printed as index on the left and value on the right.


Option 2: the default index 0, 1, 2 is used only when a list is passed, not a dictionary.

Option 3: a Series has just one index and one column of values, so the integer index is not added on top of the keys.

Option 4: this swaps keys and values; the keys are always the index.

Real output also ends with a line dtype: object, which the options leave out.

Keyboard Shortcuts

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