私はpythonに新しいです。実際に私はXMLを解析することができますが、これをExcelに書き込む方法はわかりません。python - excelに書き込む
サンプルXML:
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
私のコード:
import xml.etree.ElementTree as etree
xmld = etree.parse('simple.xml')
root = xmld.getroot()
for child in root:
for children in child:
print children.tag," : % s" %children.text
出力:
name : Belgian Waffles
price : $5.95
description : Two of our famous Belgian Waffles with plenty of real maple syrup
calories : 650
name : Strawberry Belgian Waffles
price : $7.95
description : Light Belgian waffles covered with strawberries and whipped cream
calories : 900
列Aに
'タグ' などのExcelにこれを記述する必要があります列に「値」を入力しますB enter image description here
xlwtで試してみましたまたはopenpyxlや運をpandas..butない... plsはこのサイトから...
あなたの出力から辞書を作ってから、それからデータフレームを作り、それをExcelファイルに書き込んでみてください。 –
この問題は実際のものですか、それとも答えがありますか? –
こんにちはVlad ... yepはopenpyxlのように試しました: "zip({children.tag}、{children.text})の行: ws.append(行) wb.save(" simple.xls " ) " 私は期待どおりの出力を得ることができます。どうもありがとう!!!! –