How do solve IndexError: single positional indexer is out-of-bounds?

你说的曾经没有我的故事 提交于 2019-12-25 01:48:58

问题


My expected output is as follow:

report_num|data
1           rr
1           r
1           a

However, I have problem with 'Series' object has no attribute 'value' and index is out of bound.I also have tried change iloc[0] to loc[] or loc[:0].But didnt work.Hoping someone can help.

def report_num(xml_file,df_cols):
    global df
    xtree = et.parse(xml_file)
    xroot = xtree.getroot()
    out_xml = pd.DataFrame(columns=df_cols)

    for node in xroot.findall('r:ReportHeader/r:Section[1]/r:Subreport/r:Details/r:Section[3]/r:Field',namespace):
        name = node.attrib.get('Name')
        value = node.find('r:Value',namespace).text
        out_xml = out_xml.append(
            pd.Series([value], index=df_cols), ignore_index=True)
    # df=out_xml.transpose-->if uncomment this will 'Series' object has no attribute 'value'

    return out_xml

def appendReportNum(path):
    report_num_df = rd.report_num(path, ['value'])
    report_number = report_num_df.iloc[0].value
    return report_number

def powTestC1():
    filelist = []
    pathh = r'C:/tester'
    for root, dirs, files in os.walk(pathh):
        for file in files:
            if file.endswith('.xml'):
                filelist.append(file)

        mainDf = pd.DataFrame()
        for filename in filelist:
            path = r'C:/tester/' + filename
            df = rd.pow_testparameter1(path, ['value'])
            report_num = appendReportNum(path)
            df.insert(0, "report_num", report_num)
            cond = con.condition_pow1(path, ['value'])
            rules = cond.iloc[0].value
            df.insert(1, "condition", rules)
            mainDf = pd.concat([mainDf, df])

        return mainDf

print(powTestC1())

来源:https://stackoverflow.com/questions/58848561/how-do-solve-indexerror-single-positional-indexer-is-out-of-bounds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!