XML в Datafreme - PullRequest
       1

XML в Datafreme

0 голосов
/ 24 ноября 2018

Мой код не помещает значения в Datafeame - все Нет, пожалуйста, помогите найти ошибку.Первоначально я взял код fron = m здесь http://gokhanatil.com/2017/11/python-for-data-science-importing-xml-to-pandas-dataframe.html#comment-414932

мой кусок 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>

мой код

 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()

1 Ответ

0 голосов
/ 24 ноября 2018

Я бы написал комментарий, но пока не могу.

Правильно ли указан ваш XML-файл?Кажется, вам не хватает открывающего тега в xml, одного из пространств имен:

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

Кроме того, тег <infoTable> не закрыт

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...