Constructing DataFrame from values in variables yields "ValueError: If using all scalar values, you must pass an index"
Full error message
I have two variables as follows.
a = 2
b = 3
I want to construct a DataFrame from this:
df2 = pd.DataFrame({'A':a, 'B':b})
This generates an error:
ValueError: If using all scalar values, you must pass an index
I tried this also:
df2 = (pd.DataFrame({'a':a, 'b':b})).reset_index()
This gives the same error message. How do I do what I want?Solutionsource: stackoverflow \u2197
The error message says that if you're passing scalar values, you have to pass an index. So you can either not use scalar values for the columns -- e.g. use a list: >>> df = pd.DataFrame({'A': [a], 'B': [b]}) >>> df A B 0 2 3 or use scalar values and pass an index: >>> df = pd.DataFrame({'A': a, 'B': b}, index=[0, 3]) >>> df A B 0 2 3 3 2 3
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/5d5f5be85e674aa199acce512f56663a4b1d0a4c5d19822d5bcfcf283e01fe03hash \u00b7 5d5f5be85e674aa199acce512f56663a4b1d0a4c5d19822d5bcfcf283e01fe03