小编hey*_*u91的帖子

有没有办法可以读取dataframe.to_json(orient ='table')保存的JSON文件?

我最近更新到pandas 0.20.1并尝试使用to_json的新功能(orient ='table')

import pandas as pd
pd.__version__
# '0.20.1'

a = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})
a.to_json('a.json', orient='table')
Run Code Online (Sandbox Code Playgroud)

但是如何将此JSON文件读取到DataFrame?

我尝试了,pd.read_json('a.json', orient='table')但它提出了ValueError

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-7527b25107ef> in <module>()
----> 1 pd.read_json('a.json', orient='table')

C:\Anaconda3\lib\site-packages\pandas\io\json\json.py in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, lines)
    352         obj = FrameParser(json, orient, dtype, convert_axes, convert_dates,
    353                           keep_default_dates, numpy, precise_float,
--> 354                           date_unit).parse()
    355 
    356     if typ == 'series' or obj is None:

C:\Anaconda3\lib\site-packages\pandas\io\json\json.py in parse(self)
    420 
    421 …
Run Code Online (Sandbox Code Playgroud)

python json pandas

2
推荐指数
1
解决办法
550
查看次数

标签 统计

json ×1

pandas ×1

python ×1