Convert XML to DataFrame in Python using pandas - Part #1

preview_player
Показать описание
In this video I will introduce some basics for the demo so that you can follow the demo in Part #2 easily.

XML Data:

Part #2 Demo
Рекомендации по теме
Комментарии
Автор

Dear Sir,

Thank you so much for your post it's really helpful, but I have a question I need your assistant, I have nested xml file and without text all attribs how can I convert it to DataFrame

lamiakhaled
Автор

In My XML file has different child nodes and diff attributes. Example
<?xml version="1.0"?>
<issue>
<TABLE-A>
<EMPNO>1</EMPNO>
<ENAME>A</ENAME>
<SAL>100</SAL>
</TABLE-A>
<TABLE-B>
<ADDRESSID>AD1</ADDRESSID>
<STREET>A</STREET>
<LINE>FIRST LANNE</LINE>

</TABLE-B>
</issue>

Now want to create two data frames like Table-A and Table-B using python

Can you please help me(sent mail to you for help

sumaa
Автор

Thanks for your post, it really helps, but i have one more challenge here, if I have any attributes like ( Name = 'USA' or name = 'Austria"), need those attributes also to be retrieved like other elements in DataFrame. Can you help us?
ex: consider the below xml file:
<?xml version="1.0"?>
<data>
<country name="USA">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="INDIA">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="PERU">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
Expecting output like below:





PERU 68 2011 13600 Costa Rica W

sugapriyansoundararajan
visit shbcf.ru