. Advertisement .
..3..
. Advertisement .
..4..
I get ”if using all scalar values, you must pass an index” error when i run this code:
import pandas as pd
#define scalar values
a = 1
b = 2
c = 3
d = 4
#attempt to create DataFrame from scalar values
df = pd.DataFrame({'A': a, 'B': b, 'C': c, 'D': d})
ValueError: If using all scalar values, you must pass an index
Can you give me some advice to fix it?
The cause: I think the cause of this error is that only scalar values has been passed to the DataFrame, yet an index hasn”t been passed.
The solution: You can fix this problem by transforming Scalar Values to List as the following:
Note: You should separate between the code and the error message to make it easier to read and understand the problems you’re encountering