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.convert('your_file.xml')
print(df)

Advanced Usage

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

# Control root tag preservation
df = xml_to_pandas.convert('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.2.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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xml_to_pandas-0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5ccd777825852aabbbbe7b47a34c72c259f9d6f6428f4035bf25b604c5ca57be
MD5 480edfcc3633bfd9661219054fa774db
BLAKE2b-256 21726be9f9b097828d1e56a9ec68a8bbc29f8b99cd8503b46fc0433ebca26d7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xml_to_pandas-0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d72729dd43e393ce9f32ebfb938c4ccdc61c738c7ff288c02144e4c8504e45f3
MD5 300a7f4f5dbbf36cf9b0d6a857d80213
BLAKE2b-256 e35ce5b96b56cda952e94b4d85bd29ba182e1e9488bcbd3f55f82a43f4f0bbca

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