Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

import xml.etree.ElementTree as ET import pandas as pd from collections import…

  1. User

    import xml.etree.ElementTree as ET import pandas as pd from collections import OrderedDict

    tree = ET.parse('report_f1619e94_7957_4aa6_bdfc_f21e60ec9ce6_OfSite_2024_10_04_265617.xml') root = tree.getroot()

    def extract_data(element): data = OrderedDict() for child in element: if len(child) > 0: data[child.tag] = extract_data(child) else: data[child.tag] = child.text return data

    data = extract_data(root)

    def flatten_ordered_dict(d, parent_key='', sep='.'): items = [] for k, v in d.items(): new_key = f"{parent_key}{sep}{k}" if parent_key else k if isinstance(v, OrderedDict): items.extend(flatten_ordered_dict(v, new_key, sep=sep).items()) else: items.append((new_key, v)) return OrderedDict(items)

    flat_data = flatten_ordered_dict(data)

    df = pd.DataFrame([flat_data])

    df['fio_cad_ingineer'] = df.apply( lambda row: f"{row['land_record.cad_works.cad_work.fio_cad_ingineer.surname']} {row['land_record.cad_works.cad_work.fio_cad_ingineer.name']} {row['land_record.cad_works.cad_work.fio_cad_ingineer.patronymic']}", axis=1 )

    df['fio_individual'] = df.apply( lambda row: f"{row['restrict_records.restrict_record.right_holders.right_holder.individual.surname']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.name']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.patronymic']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.birth_date']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.birth_place']}", axis=1 )

    df['identity_doc'] = df.apply( lambda row: f"{row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_name']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_series']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_number']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_date']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_issuer']}", axis=1 )

    columns_to_keep = [ 'land_record.object.common_data.cad_number', 'land_record.object.common_data.quarter_cad_number', 'details_statement.group_top_requisites.registration_number', 'land_record.params.category.type.value', 'land_record.params.permitted_use.permitted_use_established.by_document', 'land_record.address_location.address.readable_address', 'land_record.cad_works.cad_work.work_type', 'fio_cad_ingineer', 'land_record.cad_works.cad_work.cadastral_engineer_registry_number', 'land_record.special_notes', 'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.number', 'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.name_by_doc', 'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.code', 'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.value', 'land_record.restrictions_encumbrances.restriction_encumbrance.content_restrict_encumbrances', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.code', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.value', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_name', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_number', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_date', 'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_issuer', 'land_record.restrictions_encumbrances.restriction_encumbrance.starting_date', 'restrict_records.restrict_record.record_info.registration_date', 'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_number', 'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.code', 'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.value', 'restrict_records.restrict_record.restrictions_encumbrances_data.period.period_info.start_date', 'fio_individual', 'restrict_records.restrict_record.right_holders.right_holder.individual.citizenship.person_citizenship_country.citizenship_country.value', 'restrict_records.restrict_record.right_holders.right_holder.individual.snils', 'identity_doc', 'restrict_records.restrict_record.underlying_documents.underlying_document.document_code.value', 'restrict_records.restrict_record.underlying_documents.underlying_document.document_name', 'deal_records.deal_record.deal_data.deal_type.value', 'recipient_statement', 'status' ]

    df = df.filter(items=columns_to_keep)

    df.to_excel('output.xlsx', index=False)

    нужно что бы программа брала не только один xml файл а все xml которые находятся в одной папке

  2. Assistant

    To modify the program to process all XML files within a directory, you can use the os module to list all XML files in the specified directory, then iterate over each file and process it using your existing code. Here's how you can do it:

    import os
    import xml.etree.ElementTree as ET
    import pandas as pd
    from collections import OrderedDict
    
    def extract_data(element):
        data = OrderedDict()
        for child in element:
            if len(child) > 0:
                data[child.tag] = extract_data(child)
            else:
                data[child.tag] = child.text
        return data
    
    def flatten_ordered_dict(d, parent_key='', sep='.'):
        items = []
        for k, v in d.items():
            new_key = f"{parent_key}{sep}{k}" if parent_key else k
            if isinstance(v, OrderedDict):
                items.extend(flatten_ordered_dict(v, new_key, sep=sep).items())
            else:
                items.append((new_key, v))
        return OrderedDict(items)
    
    def process_xml_file(file_path):
        tree = ET.parse(file_path)
        root = tree.getroot()
        data = extract_data(root)
        flat_data = flatten_ordered_dict(data)
    
        df = pd.DataFrame([flat_data])
    
        df['fio_cad_ingineer'] = df.apply(
            lambda row: f"{row['land_record.cad_works.cad_work.fio_cad_ingineer.surname']} {row['land_record.cad_works.cad_work.fio_cad_ingineer.name']} {row['land_record.cad_works.cad_work.fio_cad_ingineer.patronymic']}",
            axis=1
        )
    
        df['fio_individual'] = df.apply(
            lambda row: f"{row['restrict_records.restrict_record.right_holders.right_holder.individual.surname']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.name']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.patronymic']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.birth_date']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.birth_place']}",
            axis=1
        )
    
        df['identity_doc'] = df.apply(
            lambda row: f"{row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_name']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_series']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_number']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_date']} {row['restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_issuer']}",
            axis=1
        )
    
        columns_to_keep = [
            'land_record.object.common_data.cad_number',
            'land_record.object.common_data.quarter_cad_number',
            'details_statement.group_top_requisites.registration_number',
            'land_record.params.category.type.value',
            'land_record.params.permitted_use.permitted_use_established.by_document',
            'land_record.address_location.address.readable_address',
            'land_record.cad_works.cad_work.work_type',
            'fio_cad_ingineer',
            'land_record.cad_works.cad_work.cadastral_engineer_registry_number',
            'land_record.special_notes',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.name_by_doc',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.content_restrict_encumbrances',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_name',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_date',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_issuer',
            'land_record.restrictions_encumbrances.restriction_encumbrance.starting_date',
            'restrict_records.restrict_record.record_info.registration_date',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_number',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.code',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.value',
            'restrict_records.restrict_record.restrictions_encumbrances_data.period.period_info.start_date',
            'fio_individual',
            'restrict_records.restrict_record.right_holders.right_holder.individual.citizenship.person_citizenship_country.citizenship_country.value',
            'restrict_records.restrict_record.right_holders.right_holder.individual.snils',
            'identity_doc',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_code.value',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_name',
            'deal_records.deal_record.deal_data.deal_type.value',
            'recipient_statement',
            'status'
        ]
    
        df = df.filter(items=columns_to_keep)
        return df
    
    directory_path = 'path/to/your/directory'
    all_files_data = []
    
    for filename in os.listdir(directory_path):
        if filename.endswith('.xml'):
            file_path = os.path.join(directory_path, filename)
            df = process_xml_file(file_path)
            all_files_data.append(df)
    
    final_df = pd.concat(all_files_data, ignore_index=True)
    final_df.to_excel('output.xlsx', index=False)
    

    Explanation

    • Directory Path: Replace 'path/to/your/directory' with the actual path to the directory containing your XML files.
    • File Processing: The code iterates over each XML file in the specified directory, processes it using the process_xml_file function, and appends the resulting DataFrame to a list.
    • Concatenation and Output: All individual DataFrames are concatenated into a single one, which is then exported to an Excel file (output.xlsx). This file will contain the combined data from all XML files.

    Make sure you have the necessary permissions to read the files in the directory and write to the output location.

  3. User

    это программа будет использоваться как exe программа и должна будет брать xml файлы из папки куда её положат

  4. Assistant

    To create a Python script that processes XML files from the same directory it's placed in and package it into an executable (.exe) file, you can follow these steps:

    1. Modify the Script to Use the Current Directory:

      • Use os.path.dirname(sys.argv[0]) to get the directory where the script/executable is located.
    2. Use a Packaging Tool:

      • Use tools like PyInstaller to package the script into an executable.

    Here is the modified script that reads XML files from the directory the executable is placed in:

    import os
    import sys
    import xml.etree.ElementTree as ET
    import pandas as pd
    from collections import OrderedDict
    
    def extract_data(element):
        data = OrderedDict()
        for child in element:
            if len(child) > 0:
                data[child.tag] = extract_data(child)
            else:
                data[child.tag] = child.text
        return data
    
    def flatten_ordered_dict(d, parent_key='', sep='.'):
        items = []
        for k, v in d.items():
            new_key = f"{parent_key}{sep}{k}" if parent_key else k
            if isinstance(v, OrderedDict):
                items.extend(flatten_ordered_dict(v, new_key, sep=sep).items())
            else:
                items.append((new_key, v))
        return OrderedDict(items)
    
    def process_xml_file(file_path):
        tree = ET.parse(file_path)
        root = tree.getroot()
        data = extract_data(root)
        flat_data = flatten_ordered_dict(data)
    
        df = pd.DataFrame([flat_data])
    
        df['fio_cad_ingineer'] = df.apply(
            lambda row: f"{row.get('land_record.cad_works.cad_work.fio_cad_ingineer.surname', '')} {row.get('land_record.cad_works.cad_work.fio_cad_ingineer.name', '')} {row.get('land_record.cad_works.cad_work.fio_cad_ingineer.patronymic', '')}",
            axis=1
        )
    
        df['fio_individual'] = df.apply(
            lambda row: f"{row.get('restrict_records.restrict_record.right_holders.right_holder.individual.surname', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.name', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.patronymic', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.birth_date', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.birth_place', '')}",
            axis=1
        )
    
        df['identity_doc'] = df.apply(
            lambda row: f"{row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_name', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_series', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_number', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_date', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_issuer', '')}",
            axis=1
        )
    
        columns_to_keep = [
            'land_record.object.common_data.cad_number',
            'land_record.object.common_data.quarter_cad_number',
            'details_statement.group_top_requisites.registration_number',
            'land_record.params.category.type.value',
            'land_record.params.permitted_use.permitted_use_established.by_document',
            'land_record.address_location.address.readable_address',
            'land_record.cad_works.cad_work.work_type',
            'fio_cad_ingineer',
            'land_record.cad_works.cad_work.cadastral_engineer_registry_number',
            'land_record.special_notes',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.name_by_doc',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.content_restrict_encumbrances',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_name',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_date',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_issuer',
            'land_record.restrictions_encumbrances.restriction_encumbrance.starting_date',
            'restrict_records.restrict_record.record_info.registration_date',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_number',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.code',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.value',
            'restrict_records.restrict_record.restrictions_encumbrances_data.period.period_info.start_date',
            'fio_individual',
            'restrict_records.restrict_record.right_holders.right_holder.individual.citizenship.person_citizenship_country.citizenship_country.value',
            'restrict_records.restrict_record.right_holders.right_holder.individual.snils',
            'identity_doc',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_code.value',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_name',
            'deal_records.deal_record.deal_data.deal_type.value',
            'recipient_statement',
            'status'
        ]
    
        df = df.filter(items=columns_to_keep)
        return df
    
    if __name__ == "__main__":
        # Determine the directory where the executable or script is located
        directory_path = os.path.dirname(sys.argv[0])
        all_files_data = []
    
        for filename in os.listdir(directory_path):
            if filename.endswith('.xml'):
                file_path = os.path.join(directory_path, filename)
                df = process_xml_file(file_path)
                all_files_data.append(df)
    
        if all_files_data:
            final_df = pd.concat(all_files_data, ignore_index=True)
            final_df.to_excel('output.xlsx', index=False)
        else:
            print("No XML files found in the directory.")
    

    Converting to an Executable with PyInstaller

    1. Install PyInstaller:

      • Open a terminal or command prompt and run:
        pip install pyinstaller
        
    2. Create the Executable:

      • Navigate to the directory containing your script using the terminal or command prompt.
      • Run the following command:
        pyinstaller --onefile your_script_name.py
        
    3. Distribution:

      • PyInstaller will create a dist folder containing the executable file. Copy this executable to any directory where you have XML files to process.
    4. Running the Executable:

      • Simply double-click the executable to run it. It will output an output.xlsx file in the same directory as the executable.

    This setup ensures that the program processes XML files in the same folder it is placed, making it adaptable for any environment without requiring changes to the script's internal configurations.

  5. User

    на русском

  6. Assistant

    Чтобы создать программу на Python, которая будет обрабатывать XML-файлы из той же папки, в которую вы её поместите, и чтобы создать исполняемый файл (.exe), вы можете выполнить следующие шаги:

    1. Модификация скрипта для работы с текущей папкой:

      • Используйте os.path.dirname(sys.argv[0]), чтобы получить путь к папке, в которой находится ваш скрипт или исполняемый файл.
    2. Использование средства упаковки:

      • Используйте такие инструменты, как PyInstaller, чтобы упаковать скрипт в исполняемый файл.

    Вот модифицированный скрипт, который читает XML-файлы из папки, в которой находится исполняемый файл:

    import os
    import sys
    import xml.etree.ElementTree as ET
    import pandas as pd
    from collections import OrderedDict
    
    def extract_data(element):
        data = OrderedDict()
        for child in element:
            if len(child) > 0:
                data[child.tag] = extract_data(child)
            else:
                data[child.tag] = child.text
        return data
    
    def flatten_ordered_dict(d, parent_key='', sep='.'):
        items = []
        for k, v in d.items():
            new_key = f"{parent_key}{sep}{k}" if parent_key else k
            if isinstance(v, OrderedDict):
                items.extend(flatten_ordered_dict(v, new_key, sep=sep).items())
            else:
                items.append((new_key, v))
        return OrderedDict(items)
    
    def process_xml_file(file_path):
        tree = ET.parse(file_path)
        root = tree.getroot()
        data = extract_data(root)
        flat_data = flatten_ordered_dict(data)
    
        df = pd.DataFrame([flat_data])
        
        # Объединение данных для инженера-землеустроителя
        df['fio_cad_ingineer'] = df.apply(
            lambda row: f"{row.get('land_record.cad_works.cad_work.fio_cad_ingineer.surname', '')} {row.get('land_record.cad_works.cad_work.fio_cad_ingineer.name', '')} {row.get('land_record.cad_works.cad_work.fio_cad_ingineer.patronymic', '')}",
            axis=1
        )
    
        # Объединение данных для физического лица
        df['fio_individual'] = df.apply(
            lambda row: f"{row.get('restrict_records.restrict_record.right_holders.right_holder.individual.surname', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.name', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.patronymic', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.birth_date', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.birth_place', '')}",
            axis=1
        )
    
        # Объединение данных для документа, удостоверяющего личность
        df['identity_doc'] = df.apply(
            lambda row: f"{row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_name', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_series', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_number', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_date', '')} {row.get('restrict_records.restrict_record.right_holders.right_holder.individual.identity_doc.document_issuer', '')}",
            axis=1
        )
    
        columns_to_keep = [
            'land_record.object.common_data.cad_number',
            'land_record.object.common_data.quarter_cad_number',
            'details_statement.group_top_requisites.registration_number',
            'land_record.params.category.type.value',
            'land_record.params.permitted_use.permitted_use_established.by_document',
            'land_record.address_location.address.readable_address',
            'land_record.cad_works.cad_work.work_type',
            'fio_cad_ingineer',
            'land_record.cad_works.cad_work.cadastral_engineer_registry_number',
            'land_record.special_notes',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.name_by_doc',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.cad_link.reg_number_border.type_zone.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.content_restrict_encumbrances',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.code',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_code.value',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_name',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_number',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_date',
            'land_record.restrictions_encumbrances.restriction_encumbrance.underlying_docs.underlying_document.document_issuer',
            'land_record.restrictions_encumbrances.restriction_encumbrance.starting_date',
            'restrict_records.restrict_record.record_info.registration_date',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_number',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.code',
            'restrict_records.restrict_record.restrictions_encumbrances_data.restriction_encumbrance_type.value',
            'restrict_records.restrict_record.restrictions_encumbrances_data.period.period_info.start_date',
            'fio_individual',
            'restrict_records.restrict_record.right_holders.right_holder.individual.citizenship.person_citizenship_country.citizenship_country.value',
            'restrict_records.restrict_record.right_holders.right_holder.individual.snils',
            'identity_doc',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_code.value',
            'restrict_records.restrict_record.underlying_documents.underlying_document.document_name',
            'deal_records.deal_record.deal_data.deal_type.value',
            'recipient_statement',
            'status'
        ]
    
        df = df.filter(items=columns_to_keep)
        return df
    
    if __name__ == "__main__":
        # Определяем папку, где расположен скрипт или исполняемый файл
        directory_path = os.path.dirname(sys.argv[0])
        all_files_data = []
    
        for filename in os.listdir(directory_path):
            if filename.endswith('.xml'):
                file_path = os.path.join(directory_path, filename)
                df = process_xml_file(file_path)
                all_files_data.append(df)
    
        if all_files_data:
            final_df = pd.concat(all_files_data, ignore_index=True)
            final_df.to_excel('output.xlsx', index=False)
        else:
            print("В папке не найдены XML файлы.")
    

    Как конвертировать в исполняемый файл с помощью PyInstaller

    1. Установите PyInstaller:

      • Откройте терминал или командную строку и выполните:
        pip install pyinstaller
        
    2. Создайте исполняемый файл:

      • Перейдите в каталог с вашим скриптом с использованием терминала или командной строки.
      • Выполните следующую команду:
        pyinstaller --onefile your_script_name.py
        
    3. Дистрибуция:

      • PyInstaller создаст папку dist, содержащую исполняемый файл. Переместите этот исполняемый файл в любую папку, где у вас есть XML-файлы для обработки.
    4. Запуск исполняемого файла:

      • Просто дважды щелкните на исполняемом файле, чтобы запустить его. Вывод будет записан в файл output.xlsx в той же папке, где вы расположили исполняемый файл.

    Таким образом, программа будет обрабатывать XML-файлы в той же папке, где она расположена, что позволяет использовать её в любой среде без изменения внутрискриптовых настроек.