Skip to main contentSkip to solution

Arrange the following python statement for creation of Series from Dictionary:

(A) print(dict1)

(B) print(series1)

(C) dict1 = {'India': 'NewDelhi', 'UK': 'London', 'Japan': 'Tokyo'}

(D) series1 = pd.Series(dict1)

Solution

✅ Correct Option: 4

(C) dict1 = {'India': 'NewDelhi', 'UK': 'London', 'Japan': 'Tokyo'} creates the dictionary first.

(A) print(dict1) displays the dictionary.

(D) series1 = pd.Series(dict1) converts the dictionary into a Series, with keys as the index and values as the data.

(B) print(series1) displays the Series.


Options 1, 2 and 3: each uses a variable before it is defined (dict1 in Options 1 and 3, series1 in Option 2), which gives a NameError.

Keyboard Shortcuts

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