Question:

Rohit is trying to create a Pandas Series from scalar values. His code has some mistakes. Rewrite the correct code and mention the corrections made.
Given code with mistakes:
import pandas

data = [50, 15, 40]

series = pd.series(data, Index=['x', 'y', 'z'])

Print(series)

Show Hint

Always check spelling and letter casing — Python and pandas are case-sensitive.
Updated On: Jul 14, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Corrected code:
import pandas as pd

data = [50, 15, 40]

series = pd.Series(data, index=['x', 'y', 'z'])

print(series)

Corrections made:
1. Added `as pd` to properly alias the pandas library so `pd` can be used.
2. Changed `series` to `Series` — class names in pandas start with a capital letter.
3. Changed `Index` to `index` — parameter names must be lowercase.
4. Changed `Print` to `print` — Python built-in functions use lowercase letters.
These corrections ensure the Series is created correctly with index labels and the output is displayed without error.
Was this answer helpful?
0
0

Top Questions on Python Libraries

View More Questions