Skip to content
Advertisement

Extracting items from xml file and make a dataframe with python

I am trying to extract the following values from an xml file: NAME, Mode,LEVELS,Group,Type and after I want to make data.frame. The problem I having so far is that I cannot get <Name>ALICE</Name> variables and output data.frame format is different than I need.

Here is the some post that I used when I built my read_xml function

  1. https://www.geeksforgeeks.org/xml-parsing-python/
  2. Extracting text from XML using python
  3. How do I parse XML in Python?

here is the example xml file format

JavaScript

I built the following function;

JavaScript

giving me this output

JavaScript

the expected output

JavaScript

How can I get the expected output!!

Thx!

Advertisement

Answer

If tag is Name in loop then set to variable and last add to dictionary values:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement