zoukankan      html  css  js  c++  java
  • Python错误 ValueError: If using all scalar values, you must pass an index.

    在使用 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)

  • 相关阅读:
    学无止境,我爱python
    Flask目录
    Django目录
    前端目录
    python目录
    MySQL目录
    Oracle与Sql server的区别
    Git
    restful规范
    Django 解决跨域问题(写入到中间件中)
  • 原文地址:https://www.cnblogs.com/wqbin/p/13844910.html
Copyright © 2011-2022 走看看