Which action will take place as a result of the following code segment?
import numpy as np
import pandas as pd
array1= np.array([1, 2, 3, 4])
series1 = pd.Series(array1)
Which action will take place as a result of the following code segment?
import numpy as np
import pandas as pd
array1= np.array([1, 2, 3, 4])
series1 = pd.Series(array1)
Solution
✅ Correct Option: 1
np.array([1, 2, 3, 4]) creates a one-dimensional NumPy array. pd.Series(array1) then passes that array to the Series constructor, so a pandas Series is built from the NumPy array. Its index defaults to 0, 1, 2, 3.
Option 2: this is the reverse direction. A Series becomes a NumPy array only with series1.values or series1.to_numpy().
Option 4: a DataFrame needs pd.DataFrame(...). pd.Series(...) always returns a Series.
Related questions:
2026: 20 May Shift 1
2025: 13 May Shift 2
2026: 23 May Shift 2
2025: 20 May Shift 1
2026: 23 May Shift 1
2026: 21 May Shift 1