If using all scalar values, you must pass an index
Package:
pandas
30911

Exception Class:
ValueError
Raise code
have_dicts = True
indexes.append(list(val.keys()))
elif is_list_like(val) and getattr(val, "ndim", 1) == 1:
have_raw_arrays = True
raw_lengths.append(len(val))
if not indexes and not raw_lengths:
raise ValueError("If using all scalar values, you must pass an index")
if have_series:
index = union_indexes(indexes)
elif have_dicts:
index = union_indexes(indexes, sort=False)
if have_raw_arrays:
Links to the raise (1)
https://github.com/pandas-dev/pandas/blob/b3e335254f46a526ee3ce9bb757eac4011d9d1fe/pandas/core/internals/construction.py#L633Ways to fix
Error code:
import pandas as pd
df = pd.DataFrame({'A':3,'B':2})
print(df)
When defining scalar variables as a column, you have to make sure that values are in the list like
or you defined index
argument.
Fix code (1):
import pandas as pd
df = pd.DataFrame({'A':3,'B':2},index=[1])
print(df)
Fix code(2):
import pandas as pd
df = pd.DataFrame({'A':[3],'B':[2]})
print(df)
Add a possible fix
Please authorize to post fix