使用python+pandas将json导入excel

2024-05-06 15:53:31 发布

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

我有一个json文件,格式如下:

<Response>
<body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Container">
    <List>
        <date>2015-01-01T00:00:00+02:00</date>
        <price>20164.654</price>
    </List>
</body>
<resultCode>0</resultCode>
<resultDescription>success</resultDescription>
</Response>

我需要的是excel表格,标签中有两列(price和date):

^{pr2}$

这看起来很简单,但我不能得到正确的结果。我得到的是:

╔═══════╦══════════════════════════╦═══════════╦══════════════════╗
║       ║           body           ║ resultCode║ ResultDescription║
╠═══════╬══════════════════════════╬═══════════╬══════════════════╣
║ List  ║ {'price': 20164.654,     ║           ║                  ║
║       ║   'date':                ║           ║                  ║
║       ║  '2015-01-01T00:00:00.   ║           ║                  ║
║       ║    000+0200'},           ║ 0         ║ success          ║    
║       ║ { ...  etc.              ║           ║                  ║
╚═══════╩══════════════════════════╩═══════════╩══════════════════╝

我用了这个简单的代码:

pandas.read_json("url").to_excel("output.xlsx")

我尝试过使用json规范化,但总是出错。在


Tags: 文件jsonhttpdateresponse格式bodyexcel