Python AttributeError:使用Windows not M时,“Series”对象没有“to”to“json”属性

2024-10-03 21:30:35 发布

您现在位置:Python中文网/ 问答频道 /正文

当Python代码在macosx上运行时,它可以正常工作。但是,当它在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系统运行的是python2.7.5和pandas v0.11.0。macosx运行的是2.7.2和pandas v0.12.0


Tags: to代码injsondataframepandas编码for
1条回答
网友
1楼 · 发布于 2024-10-03 21:30:35

API在v0.12.0中更改。在

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

v0.12.0 (July 24, 2013)

...

The I/O API is now much more consistent with a set of top level reader functions accessed like pd.read_csv() that generally return a pandas object.

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

The corresponding writer functions are object methods that are accessed like df.to_csv()

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

相关问题 更多 >