Read XML file to Pandas DataFrame

后端 未结 3 827
臣服心动
臣服心动 2020-12-11 20:30

Can someone please help convert the following XML file to Pandas dataframe:

3条回答
  •  萌比男神i
    2020-12-11 21:25

    I have had success using this function from the xmltodict package:

    import xmltodict
    
    xmlDict = xmltodict.parse(xmlData)
    df = pd.DataFrame.from_dict(xmlDict)
    

    What I like about this, is I can easily do some dictionary manipulation in between parsing the xml and making my df. Also, it helps to explore the data as a dict if the structure is wily.

提交回复
热议问题