Just wondering if someone might be able to help figure out where I’ve gone wrong on this Python script. I’m trying to read the US light list weekly changes xml (found here: https://www.navcen.uscg.gov/sites/default/files/xml/lightLists/weeklyUpdates/v7d09WeeklyChanges.xml) into a Pandas Data frame. I don’t program very often so I’m just starting off slowly, trying to write the ‘District’ field for each aid to an empty list. When I run the script it shows ‘None’ in the District column. How can I output the ‘District’ field to the dataframe? Thanks.
from lxml import etree
from lxml import objectify
import pandas as pd
import pandas_read_xml as pdx
import xml.etree.ElementTree as et
xml_file = (r'C:UsersLAWRENCEADownloadsv7d09WeeklyChanges.xml')
parsed_xml = et.parse(xml_file)
xroot = parsed_xml.getroot()
df_cols = ["District"]
rows = []
for record in xroot.iter('dataroot'):
for field in record.findall('Vol_x0020_07_x0020_D9_x0020_LL_x0020_corr_x0020_thru'):
s_District = field.attrib.get('District')
rows.append({"District": s_District})
df = pd.DataFrame(rows, columns = df_cols)
print(df)