Skip to main content

Converts all kinds of XML files to a pandas dataframe

Project description

XML to DataFrame Converter

Overview

This Python utility provides a robust and flexible solution for converting XML files into pandas DataFrames. The library offers advanced parsing capabilities that can handle complex XML structures, including nested elements, attributes, and varying node types.

Features

  • 🔄 Recursive XML parsing
  • 🌳 Handles nested and complex XML structures
  • 🏷️ Optional namespace removal
  • 📊 Converts XML to pandas DataFrame
  • 🔧 Configurable root tag preservation
  • 🚨 Comprehensive error handling and logging

Requirements

  • Python 3.7+
  • pandas
  • xml.etree.ElementTree (Standard Library)

Installation

  1. Clone the repository:
git clone https://github.com/Pi2003/xml_to_pandas.git
cd xml_to_pandas
  1. Install dependencies:
pip install pandas
pip install xml_to_pandas

Usage

Basic Example

from xml_to_pandas import xml_to_pandas

# Convert XML to DataFrame
df = xml_to_pandas('your_file.xml')
print(df)

Advanced Usage

# Ignore XML namespaces
df = xml_to_pandas('your_file.xml', ignore_namespaces=True)

# Control root tag preservation
df = xml_to_pandas('your_file.xml', preserve_root_tag=False)

Parsing Behavior

The converter handles different XML structures intelligently:

  • 📍 Leaf Nodes: Converted to single-row DataFrames
  • 🌿 Parent Nodes with Leaf Children: Concatenated side by side
  • 🌳 Parent Nodes with Parent Children: Concatenated vertically
  • 🔀 Mixed Node Types: Intelligently merged

Logging

The library uses Python's standard logging module to provide informative runtime messages:

  • File not found errors
  • XML parsing errors
  • Unexpected exceptions

Error Handling

  • Returns None for parsing failures
  • Logs detailed error messages
  • Handles various XML parsing scenarios

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Pinak Tendulkar - pdtendulkar140203@gmail.com

Project Link: https://github.com/Pi2003/xml_to_pandas

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xml_to_pandas-0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xml_to_pandas-0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file xml_to_pandas-0.1.tar.gz.

File metadata

  • Download URL: xml_to_pandas-0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for xml_to_pandas-0.1.tar.gz
Algorithm Hash digest
SHA256 4bcdc28ae1e30f9d6f5c2d0d777b0aadfa7ed055d6e8c5253482031685d7a441
MD5 335f4a1d9e1b2e07394c7f0860390ae0
BLAKE2b-256 429c2f235186e450a60ce550b786123ac8c4553937c4e727b7ebd2b5af6808ef

See more details on using hashes here.

File details

Details for the file xml_to_pandas-0.1-py3-none-any.whl.

File metadata

  • Download URL: xml_to_pandas-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for xml_to_pandas-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f62be7bcaa164e03dba7a03399db1170dc67884b99b160f1f925cc14a1b1a28
MD5 48369dfe39c698605ac1ab92be851ac0
BLAKE2b-256 4090300fcc81f7d88737db63bd186071080cc1ccd588bc6c7457bfb79745a632

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page