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.0.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.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xml_to_pandas-0.0.tar.gz
Algorithm Hash digest
SHA256 cf359ba077089b0c1fd89d66cc12ce73b8c1e5b80f0e47031f41d078bf080fbc
MD5 e2f4dd59bcdd7df0816177b1a25334e8
BLAKE2b-256 b4979ace24daa253e3af406a7f3a83e0d8d235050cda6ec29b88598d9daf542c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xml_to_pandas-0.0-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.7

File hashes

Hashes for xml_to_pandas-0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b7e2b6e0cda1d00d1fe777ba2f2db0098c2218de6e976cbf13fc50db5d101e4
MD5 0889fdc1052ccd0c7e940bc28098f54b
BLAKE2b-256 81c82f65ece9f269c4643a2adec82d10a4fc0fc651bb83c55ed164b4ac76a18e

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