def xml_to_csv(path):
"""Iterates through all .xml files in a directory and combines them into a Pandas DataFrame.
Parameters:
----------
path : str
Path to the folder containing the .xml files
Returns:
-------
pd.DataFrame
DataFrame containing XML data
"""
xml_list = []
for xml_file in glob.glob(path + '/*.xml'):
tree = ET.parse(xml_file)
root = tree.getroot()
for member in root.findall('object'):
try:
xmin = int(member.find('bndbox/xmin').text)
ymin = int(member.find('bndbox/ymin').text)
xmax = int(member.find('bndbox/xmax').text)
ymax = int(member.find('bndbox/ymax').text)
value = (root.find('filename').text,
int(root.find('size')[0].text),
int(root.find('size')[1].text),
member.find('name').text,
xmin,
ymin,
xmax,
ymax)
xml_list.append(value)
except ValueError as e:
print(f"Error processing XML file: {xml_file}. {e}")
column_name = ['filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax']
xml_df = pd.DataFrame(xml_list, columns=column_name)
return xml_df