Skip to main contentSkip to solution

Order the following steps to for creation of series from NumPy Arrays.

(A) >>> import numpy as np

(B) >>> array1 = np.array([1,2,3,4])

(C) >>> import pandas as pd

(D) >>> series3 = pd.Series(array1)

(E) >>> print(series3)

Solution

✅ Correct Option: 2

The order is (A), (C), (B), (D), (E).

(A) imports NumPy, (C) imports pandas, (B) builds the NumPy array using np, (D) converts it into a Series using pd, and (E) prints the Series.

Both imports must come before any line that uses np or pd. The array in (B) must exist before (D) can use it, and (E) comes last because it prints the finished Series.


Option 1: (D) uses array1 and pd before they are defined, and (B) uses np before it is imported in the right place.

Option 3: (B) uses np before NumPy is imported, which raises a NameError.

Option 4: (B) uses np before it is imported in (A), which raises a NameError.

Keyboard Shortcuts

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