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

Uploaded Python 3

File details

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

File metadata

  • Download URL: xml_to_pandas-0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 016b705f21f2d7336370ef20671182de08dfbaf37b2580bef574eacd62274cc0
MD5 edee4296472905aba56dba7f64ab3dfc
BLAKE2b-256 e6ab189c89838342c7560f77712d8b0879106fd6d121bf234075d60afd5ecc83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xml_to_pandas-0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3dfcf781891460a8874a35b9b6567820104e2798e5ba35b9799b237eaf9385
MD5 b740963666a95ec5905ed3166ab981a9
BLAKE2b-256 35c6de6a6a818d5e119dfff46b77fe93acd72a81b621f546743a632ba591b5e1

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