Question:

Write a Python program to create a Pandas Series as shown below from an ndarray containing the numbers 10, 20, 30, 40, 50 with corresponding indices 'A', 'B', 'C', 'D', 'E'.
Expected Series:
A    10
B    20
C    30
D    40
E    50
dtype: int64

Show Hint

Use numpy arrays with pandas when you want to easily handle numerical data with custom indices.
Updated On: Jul 14, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

To create this Series, first we need to import numpy to create the ndarray.
Then we create the Series with the given indices.
Here is the correct Python program:
import numpy as np
import pandas as pd

data = np.array([10, 20, 30, 40, 50])
index_labels = ['A', 'B', 'C', 'D', 'E']

series = pd.Series(data, index=index_labels)
print(series)

Explanation:
1. We import numpy for creating the ndarray.
2. We create an ndarray with the numbers 10, 20, 30, 40, 50.
3. We define a list of labels for the index.
4. We pass the ndarray and the index list to pd.Series() to create the labelled Series.
5. Finally, we print the Series to display it in the desired format.
This produces the output exactly as given in the question.
Was this answer helpful?
0
0

Top Questions on Python Libraries

View More Questions