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
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
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
November 26, 2021
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
June 28, 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%
🌐
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
🌐
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 - How do I convert XML to EXCEL? With Aspose.Cells for Python via NET library, you can easily convert XML to EXCEL 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.
Find elsewhere
🌐
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
🌐
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
🌐
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
🌐
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.blogs › 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.
🌐
Saturn Cloud
saturncloud.io › blog › converting-complex-xml-files-to-pandas-dataframecsv-in-python
Converting Complex XML Files to Pandas DataFrame/CSV in Python | Saturn Cloud Blog
January 11, 2019 - With this script, you can easily convert any complex XML file into a Pandas DataFrame or CSV file. This will make your data easier to work with and allow you to leverage the powerful data analysis capabilities of Python and Pandas.
🌐
E-iceblue
cdn.e-iceblue.com › Tutorials › Python › Spire.XLS-for-Python › Program-Guide › Conversion › convert-xml-to-csv-in-python.html
How to Convert XML to CSV in Python: A Complete Guide
Spire.XLS not only supports importing data from standard XML files into Excel or CSV, but also allows converting OpenXML (Microsoft's XML-based file format) to Excel. If you're interested, check out this tutorial: How to Convert Excel to OpenXML and OpenXML to Excel in Python.
🌐
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
February 2, 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.
🌐
Delft Stack
delftstack.com › home › howto › python › xml to csv python
How to Convert XML to CSV Using Python | Delft Stack
November 15, 2023 - We will use the same XML file as above and will parse this XML data, convert it to a dictionary using xmltodict, transform it into a pandas DataFrame, and finally write it to a CSV file. Here is the Python code that performs the conversion:
🌐
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