Arrange the following steps to create the series with a NumPy Array:
A. import pandas as pd
B. series3 = pd.Series(array1)
C. array1 = np.array([1,2,3,4])
D. print(series3)
Arrange the following steps to create the series with a NumPy Array:
A. import pandas as pd
B. series3 = pd.Series(array1)
C. array1 = np.array([1,2,3,4])
D. print(series3)
Solution
A, C, B, D is the only order where each name is defined before it is used.
A. import pandas as pd comes first, so that pd is available.
C. array1 = np.array([1,2,3,4]) creates the NumPy array.
B. series3 = pd.Series(array1) converts the array into a Series.
D. print(series3) displays the Series.
Options 1 and 4: pd.Series(...) is called in step B before import pandas as pd in step A, which gives a NameError.
Option 3: it starts with step B, which uses array1 and pd before either exists.
Note: np also needs import numpy as np, which is not listed among these steps.
Related questions:
2025: 20 May Shift 1
2025: 22 May Shift 1