Skip to content Skip to sidebar Skip to footer

How Can I Build An Sqlite Table From This Xml/txt File Using Python?

I have an xml/txt file like this: foo bar 11235 <

Solution 1:

Redirected from here:

How can I make sublists from a list based on strings in python?

import xml.etree.ElementTree as ET
import pandas as pd

strings = ['<text id="32a45" language="ENG" date="2017-01-01" time="11:00" timezone="Eastern">',
'<text id="32a47" language="ENG" date="2017-01-05" time="1:00" timezone="Central">',
'<text id="32a48" language="ENG" date="2017-01-07" time="3:00" timezone="Pacific">']

cols = ["id","language","date","time","timezone"]
data = [[ET.fromstring(string+"</text>").get(col) for col in cols] for string in strings]    
df = pd.DataFrame(data,columns=cols)

Post a Comment for "How Can I Build An Sqlite Table From This Xml/txt File Using Python?"