Question:medium

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

Solution and Explanation

Step 1: Work from the last line back:
The goal is print(s), where s is a Series with labels first, second and third. A Series needs data and an index, so we first find how each blank gets that data.

Step 2: Blank in the Series line:
The line reads s = pd.______(arr, ______=[...]).
The constructor in Pandas for a one-dimensional labelled object is Series, so the third blank is Series.
The argument that takes the list of labels is index, so the fourth blank is index.

Step 3: Blank in the array line:
The variable arr must be a NumPy array made from a list of three letters. The NumPy function for this is array, so the second blank is array.

Step 4: Blank in the import line:
The code writes np.array, so the library must be imported under the name np. That is import numpy as np, and the first blank is numpy.

Step 5: Put the code together:
import pandas as pd
import numpy as np
arr = np.array(['a', 'b', 'c'])
s = pd.Series(arr, index=['first', 'second', 'third'])
print(s)

Running it prints the three labels with the values a, b and c, and the line dtype: object.

Final Answer:
numpy, array, Series, index.
Was this answer helpful?
0