Skip to main content
Active reading [<https://en.wikipedia.org/wiki/XML>]. Explicit syntax highlighting hints (as a result, the diff looks more extensive than it really is - use view "Side-by-side Markdown" to compare). Removed meta information (this belongs in comments).
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

I am wounder, that no one suggestUse pandas. Pandas have a function read_xml(), what is perfect for such flat xmlXML structures.

import pandas as pd

xml = """<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>"""

df = pd.read_xml(xml, xpath=".//type")
print(df)
import pandas as pd

xml = """<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>"""

df = pd.read_xml(xml, xpath=".//type")
print(df)

Output:

   foobar
0       1
1       2
   foobar
0       1
1       2

I am wounder, that no one suggest pandas. Pandas have a function read_xml(), what is perfect for such flat xml structures.

import pandas as pd

xml = """<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>"""

df = pd.read_xml(xml, xpath=".//type")
print(df)

Output:

   foobar
0       1
1       2

Use pandas. Pandas have a function read_xml(), what is perfect for such flat XML structures.

import pandas as pd

xml = """<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>"""

df = pd.read_xml(xml, xpath=".//type")
print(df)

Output:

   foobar
0       1
1       2
Source Link
Hermann12
  • 4.2k
  • 2
  • 9
  • 21

I am wounder, that no one suggest pandas. Pandas have a function read_xml(), what is perfect for such flat xml structures.

import pandas as pd

xml = """<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>"""

df = pd.read_xml(xml, xpath=".//type")
print(df)

Output:

   foobar
0       1
1       2