Skip to main content

Automated tools for quick preparation of Pandas DataFrames.

Project description

PyChisel

PyChisel is a Python package that provides automated tools for quick preparation of Pandas DataFrames. It simplifies the process of data normalization by splitting columns into reference tables, which is a common technique in data preparation and database design.

Installation

You can install PyChisel using pip:

pip install pychisel

Requirements

  • Python 3.11 or higher
  • pandas 2.0.0 or higher

Features

  • Column Splitting: Split columns in a DataFrame into reference tables, replacing original values with IDs
  • Customizable Configuration: Control how reference tables and ID columns are named
  • Inplace Operations: Choose whether to modify the original DataFrame or create a copy

Usage

Basic Usage

import pandas as pd
from pychisel.core import Splitter

# Create a sample DataFrame
df = pd.DataFrame({
    'city': ['New York', 'Los Angeles', 'Chicago', 'New York', 'Los Angeles'],
    'department': ['Sales', 'Marketing', 'Sales', 'IT', 'Sales'],
    'employee_count': [10, 15, 8, 12, 20]
})

# Initialize the Splitter
splitter = Splitter()

# Split the 'city' and 'department' columns
splitted_df, ref_tables = splitter.split(df, columns=['city', 'department'])

# The original DataFrame now has ID columns instead of the original values
print(splitted_df)

# Reference tables contain the mapping between IDs and original values
print(ref_tables['ref_city'])
print(ref_tables['ref_department'])

Using the Convenience Function

import pandas as pd
from pychisel.core import split

# Create a sample DataFrame
df = pd.DataFrame({
    'city': ['New York', 'Los Angeles', 'Chicago', 'New York', 'Los Angeles'],
    'department': ['Sales', 'Marketing', 'Sales', 'IT', 'Sales'],
    'employee_count': [10, 15, 8, 12, 20]
})

# Split the 'city' and 'department' columns using the convenience function
splitted_df, ref_tables = split(df, columns=['city', 'department'])

Advanced Configuration

import pandas as pd
from pychisel.core import Splitter

# Create a sample DataFrame
df = pd.DataFrame({
    'city': ['New York', 'Los Angeles', 'Chicago', 'New York', 'Los Angeles'],
    'department': ['Sales', 'Marketing', 'Sales', 'IT', 'Sales'],
    'employee_count': [10, 15, 8, 12, 20]
})

# Initialize the Splitter with custom configuration
splitter = Splitter(
    drop_original=False,  # Keep the original columns
    ref_prefix='dim_',    # Use 'dim_' as prefix for reference tables
    id_suffix='_key'      # Use '_key' as suffix for ID columns
)

# Split the 'city' and 'department' columns
splitted_df, ref_tables = splitter.split(df, columns=['city', 'department'])

# The DataFrame now has both original columns and ID columns
print(splitted_df)

# Reference tables are named with the custom prefix
print(ref_tables['dim_city'])
print(ref_tables['dim_department'])

License

This project is licensed under the MIT License.

Author

Anderson Alves Monteiro - GitHub

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

pychisel-0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

pychisel-0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pychisel-0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pychisel-0.2.tar.gz
Algorithm Hash digest
SHA256 1ecc100b6b61e79ad66c11f9d3cdec8f72b65f86a27d6e6187d463043bc86cce
MD5 484637a0cd4e6b0cb740d06846535a56
BLAKE2b-256 be0a52b02f9271b0c5c762efd9321f877d2c45425c7df492fa6f0aed450c6601

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pychisel-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pychisel-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a59aeaec13dd4342cd935ee53c731dce2800e7976ae446d0ec2df8bbc701af5
MD5 57cebfba4ee989f4f376cb98edbfb413
BLAKE2b-256 19898d008a0937b383569def0ac8489d938fe82395e3f50d43355e865a6e9b4d

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