I've got the needed outcome using following script.

XML File:

<?xml version="1.0" encoding="UTF-8"?>
<base>
  <element1>element 1</element1>
  <element2>element 2</element2>
  <element3>
    <subElement3>subElement 3</subElement3>
  </element3>
</base>

Python code:

import pandas as pd
from lxml import etree

data = "C:/Path/test.xml"

tree = etree.parse(data)

lstKey = []
lstValue = []
for p in tree.iter() :
    lstKey.append(tree.getpath(p).replace("/",".")[1:])
    lstValue.append(p.text)

df = pd.DataFrame({'key' : lstKey, 'value' : lstValue})
df.sort_values('key')

Result:

Answer from Michal Hruška on Stack Overflow
🌐
Medium
medium.com › @robertopreste › from-xml-to-pandas-dataframes-9292980b1c1c
From XML to Pandas dataframes. How to parse XML files to obtain proper… | by Roberto Preste | Medium
August 25, 2019 - If we apply our function to the “students.xml” file using parse_XML("students.xml", ["name", "email", "grade", "age"]), the result is precisely the table we saw above.
People also ask

How to use the Convert XML to reStructuredText Table Online for free?
Upload your XML file, paste data, or extract from web pages using our free online table converter. Convert XML to reStructuredText instantly with real-time preview and advanced editing. This XML to reStructuredText converter lets you copy or download your reStructuredText output right away.
🌐
tableconvert.com
tableconvert.com › home › convert xml to restructuredtext table online
Convert XML to reStructuredText Table Online - Table Convert
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 reStructuredText Table format?
reStructuredText is the standard documentation format for the Python community, supporting rich table syntax, commonly used for Sphinx documentation generation.
🌐
tableconvert.com
tableconvert.com › home › convert xml to restructuredtext table online
Convert XML to reStructuredText Table Online - Table Convert
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-xml-structure-to-dataframe-using-beautifulsoup-python
Convert XML structure to DataFrame using BeautifulSoup - Python - GeeksforGeeks
March 21, 2024 - Now we have extracted the data from the XML file using the BeautifulSoup into the DataFrame and it is stored as ‘df’. To see the DataFrame we use the print statement to print it. ... # 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') pubdat
🌐
Python Forum
python-forum.io › thread-23650.html
Convert XML into DB table
January 10, 2020 - Hi, I am new to Python and also new to this forum. Please forgive and correct me if you see any posting rules are violated in this post. I am using Python version 3.8 I have a big XML file which contains the information about patient, service prov...
🌐
Saturn Cloud
saturncloud.io › blog › converting-xml-to-python-dataframe-a-comprehensive-guide
Converting XML to Python DataFrame: A Guide | Saturn Cloud Blog
November 15, 2023 - Converting XML to a Python DataFrame can be a bit tricky, but with the right approach, it becomes a straightforward task. This guide has shown you how to parse an XML file, extract the necessary data, and convert it into a DataFrame using pandas.
Top answer
1 of 4
1

Given the two levels of nodes that cover the Coluna attributes, consider XSLT, the special-purpose language designed to transform or style original XML files. Python's lxml can run XSLT 1.0 scripts and being the default parse to pandas.read_xml can transform your raw XML into a flatter version to parse to DataFrame.

XSLT (save as .xsl file, a special .xml file)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:pace='http://www.ms.com/pace'>
    <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <!-- REDESIGN XML TO ONLY RETURN AnaliseDiaria NODES -->
    <xsl:template match="/*">
     <xsl:copy>
       <xsl:apply-templates select="descendant::pace:AnaliseDiaria"/>
     </xsl:copy>
    </xsl:template>
    
    <!-- REDESIGN AnaliseDiaria NODES -->
    <xsl:template match="pace:AnaliseDiaria">
     <xsl:copy>
       <!-- BRING DOWN Produto ATTRIBUTES WITH CURRENT ATTRIBUTES -->
       <xsl:copy-of select="ancestor::pace:Produto/@*|@*"/>
     </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

Online Demo

Python

analise_diaria_df = pd.read("input.xml", stylesheet="style.xsl")

analise_diaria_df 
#        Coluna1   Coluna2  Coluna3  ...    Coluna14  Coluna15   Coluna16
# 0    21-851611  CAMIO VO      NaN  ...         NaN       NaN        NaN
# 1   21-3667984    SCA4X2     -1.0  ...         NaN       NaN        NaN
# 2   21-3667994    SCA963     -1.0  ...         NaN       NaN        NaN
# 3   21-3676543    SCA713     -1.0  ...         NaN       NaN        NaN
# 4   21-3676601     SCA97     -1.0  ...         NaN       NaN        NaN
# 5   21-3814014    CAMIX2      NaN  ...         NaN       NaN        NaN
# 6   21-3814087     SCA56      NaN  ...         NaN       NaN        NaN
# 7   21-3814087     SCA56      NaN  ...  195.000,00       NF9  10203910A
# 8   21-3814087     SCA56      NaN  ...  195.090,00       NaN        NaN
# 9   21-3814087     SCA56      NaN  ...  195.270,00       NaN        NaN
# 10  21-3814087     SCA56      NaN  ...  195.482,60       NaN        NaN
# 11  21-3814087     SCA56      NaN  ...  195.627,80       NaN        NaN
# 12  21-3814087     SCA56      NaN  ...  204.529,82       NaN        NaN
# 13  21-3814087     SCA56      NaN  ...         NaN       NaN     158PES
2 of 4
0

Fortunately, in the case of your xml in the question, you can use the pandas read_xml() method, although you'll have to skirt around the namespaces issue:

import pandas as pd
pd.read_xml(file.xml,xpath='//*[local-name()="Linha"]//*[local-name()="Produto"]')

Output:

    Coluna1        Coluna2    Coluna3     Coluna4   Coluna5     {http://www.ms.com/pace}AnaliseDiaria
0   21-851611   CAMIO VO    NaN     NaN     NaN     NaN
1   21-3667984  SCA4X2  -1.0    NaN     NaN     NaN
2   21-3667994  SCA963  -1.0    NaN     NaN     NaN

etc. If you are not interested in one column or anothter, you can simply drop() it.

Find elsewhere
🌐
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.
🌐
Table Convert
tableconvert.com › home › convert xml to restructuredtext table online
Convert XML to reStructuredText Table Online - Table Convert
January 11, 2019 - Upload XML files or paste XML data. The tool automatically parses XML structure and converts it to table format, supporting namespace, attribute handling, and complex nested structures.
🌐
Table Convert
tableconvert.com › home › convert xml to pandas dataframe online
Convert XML to Pandas DataFrame Online - Table Convert
January 11, 2019 - Generated code can be directly executed in Python environment for data analysis and processing. Extract tables from any website with one click. Convert to 30+ formats including Excel, CSV, JSON instantly - no copy-pasting required. Converting XML to PandasDataFrame?
🌐
Refitsmarthomes
refitsmarthomes.org › wp-content › uploads › 2017 › 06 › ConvertToTables.html
ConvertToTables
During the recursion, the 'tables' dictionary is populated with DataFrame tables - one for each element type """ name=element.tag.split('}')[1] if not name in tables.keys(): tables[name]=pd.DataFrame()#columns=attributes) d={} if not FK_column is None: d[FK_column]=FK_value for a in element.attrib.keys(): d[a]=element.get(a) tables[name]=tables[name].append(d,ignore_index=True) tables[name].index.name=name+'_PK' for child in element: create_tables(child,tables,name+'FK',tables[name].index.max()) tables={} create_tables(root,tables,None,None) for name in tables.keys(): tables[name].to_csv(name+'.csv')
🌐
GitHub
github.com › knadh › xmlutils.py
GitHub - knadh/xmlutils.py: Python scripts for processing XML documents and converting to SQL, CSV, and JSON [UNMAINTAINED]
Convert an XML document to an SQL file. xml2sql --input "samples/fruits.xml" --output "samples/fruits.sql" --tag "item" --table "myfruits"
Starred by 255 users
Forked by 141 users
Languages   Python 100.0% | Python 100.0%
🌐
Python
docs.python.org › 3 › library › xml.etree.elementtree.html
xml.etree.ElementTree — The ElementTree XML API
January 29, 2026 - Canonicalization is a way to normalise XML output in a way that allows byte-by-byte comparisons and digital signatures. It reduces the freedom that XML serializers have and instead generates a more constrained XML representation. The main restrictions regard the placement of namespace declarations, the ordering of attributes, and ignorable whitespace. This function takes an XML data string (xml_data) or a file path or file-like object (from_file) as input, converts it to the canonical form, and writes it out using the out file(-like) object, if provided, or returns it as a text string if not.
🌐
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
December 28, 2023 - The first step in converting an XML file to a DataFrame or CSV is parsing the XML file. We’ll use the xml.etree.ElementTree module in Python, which provides a lightweight and efficient API for parsing and creating XML data.
🌐
Notepad++ Community
community.notepad-plus-plus.org › topic › 24563 › convert-xml-data-to-tabular-csv-data-or-tab-separated-without-a-script
Convert XML data to tabular csv data or tab separated without a script | Notepad++ Community
November 13, 2024 - PythonScript makes working with XML data quite easy, because Python’s standard library has great XML support. Here’s a pretty generic script. I’ve only tested it on the sample data you provided. # based on https://community.notepad-plus-plus.org/topic/24563/convert-xml-data-to-tabular-csv-data-or-tab-separated-without-a-script # References: # * https://docs.python.org/3/library/xml.etree.elementtree.html#module-xml.etree.ElementTree # * https://docs.python.org/3/library/csv.html # * https://docs.python.org/3/library/io.html#io.StringIO # * https://npppythonscript.sourceforge.net/docs/lat
🌐
Stack Overflow
stackoverflow.com › questions › 59635922 › how-to-convert-table-into-a-specific-xml-format-using-python
How to convert table into a specific XML format using Python? - Stack Overflow
Please take a look at the python standard library xml: https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.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
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › scenarios › xml
XML parsing — The Hitchhiker's Guide to Python
untangle is a simple library which takes an XML document and returns a Python object which mirrors the nodes and attributes in its structure.