Question:

Niharika wants to create a Pandas Series using a NumPy array with three elements 'a', 'b', and 'c', and assign custom indexes 'first', 'second' and 'third'. Help her complete the code below.

import pandas as pd
import ______ as np
arr = np._____ (['a' , 'b' , 'c'])
s = pd._____(arr,_____=['first','second','third'])
print(s)

Show Hint

Import NumPy as np, make the array with np.array, and build the Series with pd.Series using the index keyword.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the code:
The program must make a Pandas Series from a NumPy array. The array holds 'a', 'b' and 'c'. The Series must carry the custom index labels first, second and third.

Step 2: Fill the import line:
The next lines use the short name np. NumPy is imported with this short name, so the first blank is numpy.
import numpy as np


Step 3: Fill the array line:
To make a NumPy array from a list, we call the function array. So the second blank is array.
arr = np.array(['a', 'b', 'c'])


Step 4: Fill the Series line:
The Pandas class that builds a Series is Series. Its first argument is the data, and the keyword index sets the labels. So the third blank is Series and the fourth blank is index.
s = pd.Series(arr, index=['first', 'second', 'third'])


Step 5: Check by running the code:
The completed program was run in Python. The print(s) line gives this output.
first     a
second    b
third     c
dtype: object


Final Answer:
The blanks are, in order: numpy, array, Series, index.
Was this answer helpful?
0
0