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)
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
(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.
Related questions:
2025: 27 May Shift 2
2026: 31 May Shift 1
2025: 21 May Shift 1
2025: 13 May Shift 2