Question:

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)
Choose the correct answer from the options given below:

Show Hint

Imports must come before the lines that use them. Series is made from array1, and print is last.
Updated On: Oct 1, 2026
  • (A), (D), (C), (B), (E)
  • (A), (C), (B), (D), (E)
  • (B), (A), (D), (C), (E)
  • (C), (B), (D), (A), (E)
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding the Concept:
Each line of code needs the names it uses to exist before it runs. A name from a library exists only after the library is imported. A variable exists only after it is assigned. So the order is decided by what each line needs.

Step 2: What each line needs.
(A) import numpy as np needs nothing. It creates the name np.
(B) array1 = np.array([1,2,3,4]) needs np, so it must come after (A).
(C) import pandas as pd needs nothing. It creates the name pd.
(D) series3 = pd.Series(array1) needs both pd from (C) and array1 from (B).
(E) print(series3) needs series3 from (D), so it is last.

Step 3: Build the order.
The two imports (A) and (C) come first, in any order. Then (B), then (D), then (E). The options give the order (A), (C), (B), (D), (E), where numpy is imported first and pandas second.

Step 4: Check option 1 (A, D, C, B, E).
(D) runs before (C) and (B). Then pd and array1 do not exist yet. This gives a NameError. So option 1 is wrong.

Step 5: Check option 2 (A, C, B, D, E).
Both imports run first. Then array1 is made, then the Series, then it is printed. Every line finds what it needs. So option 2 is correct.

Step 6: Check option 3 (B, A, D, C, E).
(B) uses np before it is imported, which gives a NameError. So option 3 is wrong.

Step 7: Check option 4 (C, B, D, A, E).
(B) uses np before (A) imports numpy, which gives a NameError. So option 4 is wrong.

Step 8: Final Answer:
The correct order is (A), (C), (B), (D), (E), which is option 2. \[ \boxed{(A),\ (C),\ (B),\ (D),\ (E)} \]
Was this answer helpful?
0
0