What will be the output of following code? Pandas Questions 3

3. What will be the output of following code?

import pandas as pnd
pnd.Series([1,2], index= ['a','b','c'])
  1. Syntax Error
  2. Index Error
  3. Value Error
  4. None of the above mentioned

Answer: C) Value Error

Explanation:

In the above code, value error will be.

Output:

raceback (most recent call last):
  File "/home/main.py", line 2, in <module>
    pnd.Series([1,2], index= ['a','b','c'])
  File "/usr/lib/python3/dist-packages/pandas/core/series.py", line 430, in __init__
    com.require_length_match(data, index)
  File "/usr/lib/python3/dist-packages/pandas/core/common.py", line 531, in require_length_match
    raise ValueError(
ValueError: Length of values (2) does not match length of index (3)

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.