【问题标题】:Python AttributeError: 'Series' object has no attribute 'to_json' when using Windows not MacPython AttributeError:“系列”对象在使用 Windows 而非 Mac 时没有属性“to_json”
【发布时间】:2013-12-19 00:08:29
【问题描述】:

当 Python 代码在 Mac OSX 上运行时,它运行良好。但是,当它在 Windows 上运行时,会引发以下错误,其中 fruitspandas.DataFrame

代码

for i, row in fruits.T.iterkv():
    data = json.loads(row.to_json())

错误:

AttributeError: 'Series' object has no attribute 'to_json'

是什么导致了这个错误?

Windows 系统运行 Python 2.7.5 和 pandas v0.11.0。 Mac OSX 使用 pandas v0.12.0 运行 2.7.2

【问题讨论】:

    标签: python json macos python-2.7 pandas


    【解决方案1】:

    API 在 v0.12.0 中有所更改。

    根据What's new - v0.12.0 (July 24, 2013)

    v0.12.0(2013 年 7 月 24 日)

    ...

    I/O API 现在与一组顶级阅读器更加一致 访问的函数如 pd.read_csv() 通常返回熊猫 对象。

    • read_csv
    • read_excel
    • read_hdf
    • read_sql
    • read_json
    • read_html
    • read_stata
    • read_clipboard

    对应的 writer 函数是对象方法,它们是 像 df.to_csv() 一样访问

    • to_csv
    • to_excel
    • to_hdf
    • to_sql
    • to_json
    • to_html
    • to_stata
    • to_clipboard

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-11
      • 2019-04-22
      • 2019-07-26
      • 2020-04-04
      • 2019-09-16
      • 2017-12-12
      • 2018-05-25
      • 2019-07-07
      相关资源
      最近更新 更多