0

I have a string of text in an XML format that I'm looking to output into a pandas dataframe. This is the string:

<period type="Day" value="2022-01-03Z"><rep d="W" dm="3" fdm="-3" gn="40" hn="81" ppd="36" s="11" u="1" v="EX" w="7">Day</rep><rep d="WNW" fnm="-4" gm="47" hm="79" nm="1" ppn="81" s="29" v="VG" w="12">Night</rep></period>

I know pandas.read_xml(x) is a good way of doing this when you have an XML file, but I'm getting'AttributeError: enter' when trying to use this on this string.

Jody
  • 115
  • 5

1 Answers1

0

I don't think your error has anything to do with the pandas.read_xml. I'm able to run this code:

import pandas

period_string = '''<period type="Day" value="2022-01-03Z"><rep d="W" dm="3" fdm="-3" gn="40" hn="81" ppd="36" s="11" u="1" v="EX" w="7">Day</rep><rep d="WNW" fnm="-4" gm="47" hm="79" nm="1" ppn="81" s="29" v="VG" w="12">Night</rep></period>'''


def read_xml_func():
    pandas.read_xml(period_string)


if __name__ == '__main__':
    read_xml_func()

About your error AttributeError: enter, Most likely, you have reassigned the Python builtin open function to something else in your code (there's almost no other plausible way this exception could be explained). As noted here: Python Error: "AttributeError: __enter__"