在使用 pandas ,使用json(dict)数据类型创建 DataFrame 时错误 ValueError: If using all scalar values, you must pass an index。
这是因为 pandas 的 DataFrame 方法需要传入一个可迭代的对象(列表,元组,字典等), 或者给 DataFrame 指定 index 参数就可以解决这个问题。如下
import pandas as pd df=pd.DataFrame({'a':2,'b':4}) print(df)
报错信息:
方法一:
import pandas as pd df=pd.DataFrame({'a':[2],'b':[4]}) print(df)
方法二:
Index(...) must be called with a collection of some kind
import pandas as pd df=pd.DataFrame({'a':2,'b':4},index=[0]) print(df)