create a csv file which is Excel friendly format.

import xml.etree.ElementTree as ET
from os import listdir


xml_lst = [f for f in listdir() if f.startswith('xml')]
fields = ['RecordID','I_25Hz_1s','I_75Hz_2s'] # TODO - add rest of the fields
with open('out.csv','w') as f:
  f.write(','.join(fields) + '\n')
  for xml in xml_lst:
    root = ET.parse(xml)
    values = [root.find(f'.//{f}').text for f in fields]
    f.write(','.join(values) + '\n')

output

RecordID,I_25Hz_1s,I_75Hz_2s
Madird01,56.40,0.36
London01,56.40,0.36
Answer from balderman on Stack Overflow
🌐
Python.org
discuss.python.org › python help
Convert xml to excel/csv - Python Help - Discussions on Python.org
October 15, 2022 - Please help me in converting XML file into excel/csv. Thank you in advance.
🌐
Like Geeks
likegeeks.com › home › python › pandas › export xml to excel using python pandas
Export XML to Excel using Python Pandas
April 27, 2025 - You can export XML files to Excel by reading the XML using Pandas read_xml() and then exporting the result DataFrame to Excel using Pandas to_excel(). ... <Customers> <Customer> <ID>1</ID> <Name>Customer A</Name> <Contact>1234567890</Contact> ...
Discussions

python - How to convert an XML file to nice pandas dataframe? - Stack Overflow
You can easily use xml (from the Python standard library) to convert to a pandas.DataFrame. More on stackoverflow.com
🌐 stackoverflow.com
How to parse XML into an excel sheet?
Depending on the complexity of the xml, the easiest way might be to simply read into a pandas dataframe and write it back out as Excel. https://pandas.pydata.org/docs/reference/api/pandas.read_xml.html# https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html More on reddit.com
🌐 r/learnpython
2
3
December 2, 2021
Parsing XML into a Pandas dataframe
To parse an XML file into a Pandas DataFrame, you can use the from_dict method of the DataFrame class. First, you will need to use the ElementTree module to parse the XML file and extract the relevant data. Here is an example of how this can be done: import xml.etree.ElementTree as ET import pandas as pd Parse the XML file using ElementTree tree = ET.parse('my_file.xml') root = tree.getroot() Extract the column names from the 'columns' element columns = [col.attrib['friendlyName'] for col in root.find('columns')] Create an empty list to store the data for each row data = [] Iterate over the 'row' elements and extract the data for each one for row in root.find('rows'): row_data = {} for col in row: # Add the data for each column to the dictionary row_data[col.attrib['name']] = col.text # Add the dictionary for this row to the list data.append(row_data) Create a DataFrame using the column names and data df = pd.DataFrame.from_dict(data, columns=columns) This code will parse the XML file and extract the data for each row and column, storing it in a dictionary. The dictionary is then used to create a DataFrame using the from_dict method. This DataFrame will have the column names as the columns and each row of data as a row in the DataFrame. More on reddit.com
🌐 r/learnpython
8
3
December 9, 2022
What’s the easiest way to convert .xml file to .xlsx?

Parsing xml isn’t something I’ve tried before, but I would probably start by trying this guy’s approach: https://link.medium.com/f6TTwmTSo2

More on reddit.com
🌐 r/learnpython
1
1
July 4, 2017
People also ask

How to use the Convert XML to Pandas DataFrame Online for free?
Upload your XML file, paste data, or extract from web pages using our free online table converter. Convert XML to PandasDataFrame instantly with real-time preview and advanced editing. This XML to PandasDataFrame converter lets you copy or download your PandasDataFrame output right away.
🌐
tableconvert.com
tableconvert.com › home › convert xml to pandas dataframe online
Convert XML to Pandas DataFrame Online - Table Convert
What is Pandas DataFrame format?
Pandas is the most popular data analysis library in Python, with DataFrame being its core data structure. It provides powerful data manipulation, cleaning, and analysis capabilities, widely used in data science, machine learning, and business intelligence. An indispensable tool for Python developers and data analysts.
🌐
tableconvert.com
tableconvert.com › home › convert xml to pandas dataframe online
Convert XML to Pandas DataFrame Online - Table Convert
What is XML format?
XML (eXtensible Markup Language) is the standard format for enterprise-level data exchange and configuration management, with strict syntax specifications and powerful validation mechanisms. Widely used in web services, configuration files, document storage, and system integration. Supports namespaces, schema validation, and XSLT transformation, making it important table data for enterprise applications.
🌐
tableconvert.com
tableconvert.com › home › convert xml to pandas dataframe online
Convert XML to Pandas DataFrame Online - Table Convert
Top answer
1 of 3
2

create a csv file which is Excel friendly format.

import xml.etree.ElementTree as ET
from os import listdir


xml_lst = [f for f in listdir() if f.startswith('xml')]
fields = ['RecordID','I_25Hz_1s','I_75Hz_2s'] # TODO - add rest of the fields
with open('out.csv','w') as f:
  f.write(','.join(fields) + '\n')
  for xml in xml_lst:
    root = ET.parse(xml)
    values = [root.find(f'.//{f}').text for f in fields]
    f.write(','.join(values) + '\n')

output

RecordID,I_25Hz_1s,I_75Hz_2s
Madird01,56.40,0.36
London01,56.40,0.36
2 of 3
1

When you need to iterate over files in folder with similar names one of the ways could be make a pattern and use glob. To make sure that returned path is file you can use isfile().

Regarding XML, I see that basically you need to write values of every terminal tag in column with name of this tag. As you have various files you can create tag-value dictionaries from each file and store them into ChainMap. After all files processed you can use DictWriter to write all data into final csv file.

This method is much more safe and flexible then use static column names. Firstly program will collect all possible tag(column) names from all files, so in case if XML doesn't have such a tag or have some extra tags it won't throw an exception and all data will be saved.

Code:

import xml.etree.ElementTree as ET
from glob import iglob
from os.path import isfile, join
from csv import DictWriter
from collections import ChainMap

xml_root = r"C:\data\Desktop\Blue\XML-files"
pattern = "xmlfile_*"
data = ChainMap()
for filename in iglob(join(xml_root, pattern)):
    if isfile(filename):
        tree = ET.parse(filename)
        root = tree.getroot()
        temp = {node.tag: node.text for node in root.iter() if not node}
        data = data.new_child(temp)

with open(join(xml_root, "data.csv"), "w", newline="") as f:
    writer = DictWriter(f, data)
    writer.writeheader()
    writer.writerows(data.maps[:-1])  # last is empty dict

Upd. If you want to use xlsx format instead of csv you have to use third-party library (e.g. openpyxl). Example of usage:

from openpyxl import Workbook

...

wb = Workbook(write_only=True)
ws = wb.create_sheet()
ws.append(list(data))  # write header
for row in data.maps[:-1]:
    ws.append([row.get(key, "") for key in data])
wb.save(join(xml_root, "data.xlsx"))
🌐
GitHub
github.com › vrushabhkaushik › XML-to-Excel-Conversion
GitHub - vrushabhkaushik/XML-to-Excel-Conversion: The python script reads the XML file name from user's input, and then using data frame, it writes the data to an Excel sheet
The python script reads the XML file name from user's input, and then using data frame, it writes the data to an Excel sheet - vrushabhkaushik/XML-to-Excel-Conversion
Starred by 5 users
Forked by 2 users
Languages   Python 100.0% | Python 100.0%
🌐
Table Convert
tableconvert.com › home › convert xml to pandas dataframe online
Convert XML to Pandas DataFrame Online - Table Convert
January 11, 2019 - Use the extension to detect and extract tables from any page, then paste the data here to convert XML to PandasDataFrame. Instantly extract tables from any webpage without copy-pasting - professional data extraction made simple · Convert extracted tables to Excel, CSV, JSON, Markdown, SQL, and more with our advanced table converter
Find elsewhere
🌐
Aspose
products.aspose.com › aspose.cells › python via .net › conversion › xml to excel
Convert XML to EXCEL in Python Excel Library - Conversion
November 13, 2025 - Aspose Excel. This comprehensive solution provides Python developers with a fully integrated approach to convert XML to EXCEL format, enabling seamless saving of XML data into EXCEL format using the Aspose.Cells library, all through efficient and customizable Python code.
🌐
EasyXLS
easyxls.com › manual › tutorials › python › convert-xml-spreadsheet-to-excel.html
Convert XML Spreadsheet to Excel file in Python | EasyXLS Guide
Code sample Python: Convert XML Spreadsheet to Excel file in Python by EasyXLS library. XLSX, XLSM, XLSB, XLS in Python
🌐
Quora
quora.com › How-can-I-convert-XML-to-Excel-using-Python-scripting
How to convert XML to Excel using Python scripting - Quora
Answer: Hi you can use regular expression to extract data. And then you can write the got results into the excel through the python script itself. Re module is used for extracting data and excel module to open and write into the excel file
🌐
PyPI
pypi.org › project › xml2xlsx
xml2xlsx · PyPI
This is a merely an xml parser translating mostly linearly to worksheet, rows and finally cells of the Excel workbook.
      » pip install xml2xlsx
    
Published   Sep 16, 2024
Version   1.0.2
🌐
Oracle
blog.toadworld.com › home › python for data science – importing xml to pandas dataframe
Python for Data Science – Importing XML to Pandas DataFrame - The Quest Blog
September 7, 2025 - In my previous post, I showed how ... JSON, Excel files using Pandas package. Another popular format to exchange data is XML. Unfortunately Pandas package does not have a function to import data from XML so we need to use standard XML package and do some extra work to convert the data to ...
🌐
Like Geeks
likegeeks.com › home › python › pandas › export xml to csv using python pandas
Export XML to CSV using Python Pandas
December 16, 2023 - Learn how to convert XML to CSV using Pandas in Python, From handling simple to complex nested XML structures efficiently.
🌐
Aspose
blog.aspose.com › aspose blog › convert xml to excel in python
Convert XML to Excel Python | Export XML to Excel in Python
March 15, 2024 - Convert XML to Excel in Python. Export data from an XML file to Excel programmatically in Python using Aspose.Cells for Python API.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-xml-structure-to-dataframe-using-beautifulsoup-python
Convert XML structure to DataFrame using BeautifulSoup - Python - GeeksforGeeks
March 21, 2024 - # Python program to convert xml # structure into dataframes using beautifulsoup # Import libraries from bs4 import BeautifulSoup import pandas as pd # Open XML file file = open("gfg.xml", 'r') # Read the contents of that file contents = file.read() soup = BeautifulSoup(contents, 'xml') # Extracting the data authors = soup.find_all('author') titles = soup.find_all('title') prices = soup.find_all('price') pubdate = soup.find_all('publish_date') genres = soup.find_all('genre') des = soup.find_all('description') data = [] # Loop to store the data in a list named 'data' for i in range(0, len(author
🌐
Delft Stack
delftstack.com › home › howto › python pandas › convert xml file to python nice pandas dataframe
How to Convert XML File to Pandas DataFrame | Delft Stack
April 21, 2024 - This tutorial introduces how an XML file is converted into a Python Pandas nice dataframe. The library used for this is the xml.etree.ElementTree.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-xml-to-csv-in-python
Convert XML to CSV in Python - GeeksforGeeks
July 23, 2025 - We used ElementTree to parse and navigate through the XML structure. Data from each record was collected into a list of dictionaries. Finally, we used pandas to create a CSV file from that structured data. To learn about the pandas module in depth, refer to: Python Pandas Tutorial
🌐
Reddit
reddit.com › r/learnpython › how to parse xml into an excel sheet?
r/learnpython on Reddit: How to parse XML into an excel sheet?
December 2, 2021 -

Bare with me, as I'm a novice with python, but basically, I am trying to take an XML file, and plop it into an existing excel workbook in a specific sheet. I know I have done this successfully before, but cannot find the file where I did, nor can I remember how I did.

When I do it manually, the process is pretty straight forward - download the XML file, open it with excel, copy and paste as text into the sheet. Just hoping someone could help me get started here. Thanks so much for your time.

To be more specific this is the layout of the XML file:

<products>

<product active="1" on_sale="0" discountable="1">

<sku>GG1234</sku>

<name><![CDATA[ Product Name Here ]]></name>

<description><![CDATA[Product Description Here ]]></description>

<keywords></keywords>

<price>8.9</price>

<stock_quantity>220</stock_quantity>

<reorder_quantity>0</reorder_quantity>

<height>4.25</height>

<length>1.25</length>

<diameter>2.5</diameter>

<weight>0.53</weight>

<color></color>

<material>Material Here/material>

<barcode>0000000000</barcode>

<release_date>2010-02-19</release_date>

<images>

<image>/path/path.jpg</image>

<image>/path/path.jpg</image>

<image>/path/path.jpg</image>

<image>/path/path.jpg</image>

</images>

<categories>

<category code="518" video="0" parent="0">Category 1</category>

<category code="525" video="0" parent="528">Category 2</category>

<category code="138" video="0" parent="0">Category 3</category>

<category code="552" video="0" parent="528">Category 4</category>

</categories>

<manufacturer code="AC" video="0">Manufact</manufacturer>

<type code="CL" video="0">Product Type</type>

</product> . . . . .

<products>

What I need is for the follow values to populate the top row as the header of the excel file:

active
on_sale
disctountable
sku
name
description
keywords
price
stock_quantity
reorder_quantity
height
length
diameter
weight
color
material
barcode
release_date
image
category
manufacturer
code2
video3
type
code4
video5

And then their respective values to populate the cells going downward in the columns.

Hope that makes sense

🌐
Aspose
products.aspose.com › aspose.cells › python via .net › conversion › xml to xlsx
Convert XML to XLSX in Python Excel Library - Conversion
November 13, 2025 - With Aspose.Cells for Python via NET library, you can easily convert XML to XLSX programmatically with a few lines of code. Aspose.Cells for Python via NET is capable of building cross-platform applications with the ability to generate, modify, convert, render and print all Excel files.