0

My code doesn't put values in Datafeame - all None, please help find mistake. Originaly I took code fron=m here http://gokhanatil.com/2017/11/python-for-data-science-importing-xml-to-pandas-dataframe.html#comment-414932

my piece of xml

    xmlns="http://www.sec.gov/edgar/document   /thirteenf/informationtable"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-   instance">
    <infoTable>
                                                  <nameOfIssuer>AMERICAN AIRLS GROUP    INC</nameOfIssuer>
   <titleOfClass>COM</titleOfClass>
   <cusip>02376R102</cusip>
   <value>857267</value>
   <shrsOrPrnAmt>
       <sshPrnamt>20742000</sshPrnamt>
       <sshPrnamtType>SH</sshPrnamtType>
   </shrsOrPrnAmt>
   <investmentDiscretion>DFND</investmentDiscretion>
   <otherManager>4</otherManager>
   <votingAuthority>
       <Sole>20742000</Sole>
       <Shared>0</Shared>
       <None>0</None>
   </votingAuthority>

my code

 import xml.etree.cElementTree as et
 import pandas as pd


def getvalueofnode(node):
    """ return node text or None """
    return node.text if node is not None else None


def main():
    """ main """
    parsed_xml = et.parse("form13fInfoTable.xml")
   dfcols = ['infoTable/nameOfIssuer', 'infotanle/cusip', 'infotable/value']
df_xml = pd.DataFrame(columns=dfcols)

for node in parsed_xml.getroot():
    print(parsed_xml.getroot())
    parsed_xml.getroot()

    nameOfIssuer = node.find('informationTable/infoTable/nameOfIssuer')
    cusip = node.find('infoTable/cusip')
    value = node.find('infoTable/value')


    df_xml =    df_xml.append(pd.Series([getvalueofnode(nameOfIssuer),getvalueofnode(cusip), getvalueofnode(value)], index=dfcols),ignore_index=True)

print(df_xml)


main()
IgBell
  • 391
  • 3
  • 4
  • 11
  • Possible duplicate of [How to convert an XML file to nice pandas dataframe?](https://stackoverflow.com/questions/28259301/how-to-convert-an-xml-file-to-nice-pandas-dataframe) – 576i Nov 24 '18 at 13:37
  • Look at https://stackoverflow.com/questions/28259301/how-to-convert-an-xml-file-to-nice-pandas-dataframe which should help. – 576i Nov 24 '18 at 13:38

1 Answers1

0

I'd write a comment, but I can't do that yet.

Is your xml file correct? It seems that you lack opening tag in your xml, one by the namespaces:

<root xmlns=... > your xml </root>

Also, the <infoTable> tag isn't closed

Adrian
  • 105
  • 2
  • 6
  • that was a piece jf xml , the original document https://www.sec.gov/Archives/edgar/data/1067983/000095012318011885/form13fInfoTable.xml – IgBell Nov 24 '18 at 19:47