0

I need some help. I have an XML file that I need to convert the data into a dataframe with python in Jupyter Notebook to do some analytics prediction on it.this is some part of an XML file enter image description here

and there is my code: enter image description here

the problem is that I can get the name values but all the values for the start and duration are none. I tried with .get instead of .find but the name values got none as well.

1 Answers1

0

Try with below code.

import xml.etree.ElementTree as ET
import pandas as pd
dfcols=['Name','Start','Duration']
df_xml=pd.DataFrame(columns=dfcols)
print(df_xml)
tree = ET.parse('test.xml')
for subchild in tree.getroot().findall('ScoreEvent'):
        Name=subchild.find('Name').text
        Start=float(subchild.find('Start').text)
        Duration=float(subchild.find('Duration').text)
        df_xml=df_xml.append(pd.DataFrame([[Name,Start,Duration]],columns=dfcols),ignore_index=True)
print(df_xml)

It worked for me