Skip to main contentSkip to solution

Arrange the following steps in the correct order to create a Pandas Series from a dictionary and displaying the elements.

A. import pandas as pd

B. s= pd.Series(data)

C. print(s)

D. data= {'A':10, 'B':20, 'C":30}

Solution

✅ Correct Option: 2

A. import pandas as pd (the library must be imported before it can be used)

D. data = {'A':10, 'B':20, 'C':30} (the dictionary must exist before the Series is built)

B. s = pd.Series(data) (builds the Series, with the keys as the index and the values as the data)

C. print(s) (displays the elements)


Options 1 and 3: B comes before D, so data is not yet defined when pd.Series(data) runs, which gives a NameError.

Option 4: C comes before B, so s does not exist when it is printed.

Keyboard Shortcuts

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