【问题标题】:How to pass XML to Excel with python (or other language)?如何使用 python(或其他语言)将 XML 传递给 Excel?
【发布时间】:2019-05-13 21:27:26
【问题描述】:

我正在尝试将 XML 传递到 Excel 表中以进行进一步分析(图表、动态表等)。我使用 wget (linux) 从 HTTP 服务器请求信息,然后将其传递给 Windows,然后我想知道一种将这个 XML 文件传递​​到表中的方法。

这适用于从 http 服务器重新收集数据的 24 个 XML 文件(每小时 1 个)。每小时请求的部分解决了,但是数据处理是我的问题。

所以 XML 文件是这样的:

<Ptexport version="1.6.0" >

<Response><RR cid="1459546492000" sid="38587" eod="0">

<RR1 direction="0" statTime="1556668838385" lostperc="0" dmax="264947" jmax="50154" />
<RR1 direction="1" statTime="1556668838385" lostperc="0" dmax="34530" jmax="16085" />
<RR1 direction="0" statTime="1556668898385" lostperc="28428" dmax="239192" jmax="21417" />
<RR1 direction="1" statTime="1556668898385" lostperc="0" dmax="40576" jmax="19246" />
<RR1 direction="0" statTime="1556668958386" lostperc="31666" dmax="257147" jmax="22487" />
<RR1 direction="1" statTime="1556668958386" lostperc="0" dmax="52772" jmax="9648" />
<RR1 direction="0" statTime="1556669018386" lostperc="36666" dmax="236172" jmax="28367" />
<RR1 direction="1" statTime="1556669018386" lostperc="0" dmax="75074" jmax="9524" />
<RR1 direction="0" statTime="1556669078385" lostperc="26711" dmax="210017" jmax="28195" />
<RR1 direction="1" statTime="1556669078385" lostperc="0" dmax="87410" jmax="11392" />
<RR1 direction="0" statTime="1556669138386" lostperc="16638" dmax="215571" jmax="23909" />
</RR>

<RR cid="1459546492000" sid="34123" eod="0">

<RR1 direction="0" statTime="1556668832391" lostperc="1000000" dmax="0" jmax="0" />
<RR1 direction="1" statTime="1556668832391" lostperc="0" dmax="0" jmax="0" />
<RR1 direction="0" statTime="1556668892391" lostperc="1000000" dmax="0" jmax="0" />
<RR1 direction="1" statTime="1556668892391" lostperc="0" dmax="0" jmax="0" />
<RR1 direction="0" statTime="1556668952391" lostperc="1000000" dmax="0" jmax="0" />
<RR1 direction="1" statTime="1556668952391" lostperc="0" dmax="0" jmax="0" />

</RR></Response></Ptexport>

所以我们可以看到一个给定时间的标签有 6 个值:

sid:在每次测量的开始,它是我正在使用的节点 ID。 RR1 方向:注册表是上游还是下游('1' 或 '0') stattime:纪元linux时间(我知道如何将它传递给人类时间,那里没问题) lostperc, dmax, jmax:电信值

所以我希望在 Excel 中显示数据,如下所示:

【问题讨论】:

  • 您的 xml 无效。您有两个 RR 开始标签,但只有一个 RR 结束标签
  • 是的,你是对的!我更正了

标签: python excel xml xml-parsing


【解决方案1】:

您需要先解析 XML。请查看 this questionthis tutorial 了解如何执行此操作。

第二部分是将数据导出到.csv 或 Excel 可以使用的其他东西。为此,请查看python's csv module

【讨论】:

  • openpyxlxlwings 在 Python 中创建/编辑 Excel 文件也非常方便。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
  • 2010-11-28
相关资源
最近更新 更多