Skip to main contentSkip to solution

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.

Keyboard Shortcuts

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