error solved

Solved – valueerror: if using all scalar values, you must pass an index


In this article, you will learn how to solve valueerror: if using all scalar values, you must pass an index error in Python.

Let’s look at a code example that produces the same error.

import pandas as pds

dict_vegetables = {
'potatao':'grey',
'tomato':'red',
'ladyfinger':'green'
}

data_frame = pds.DataFrame.from_dict(dict_vegetables)
print(data_frame)

output

File "/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py", line 7393, in extract_index
    raise ValueError('If using all scalar values, you must pass'
ValueError: If using all scalar values, you must pass an index

In order to solve valueerror: if using all scalar values, you must pass an index error in Python you need to add index values to Pandas while creating a data frame like in the code snippet below:

import pandas as pds

dict_vegetables = {
'potatao':['grey'],
'tomato':['red'],
'ladyfinger':['green']
}

data_frame = pds.DataFrame.from_dict(dict_vegetables)
print(data_frame)

output

  potatao tomato ladyfinger
0    grey    red      green

Share on social media

//