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.1.tar.gz (3.6 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.1-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pychisel-0.1.tar.gz
Algorithm Hash digest
SHA256 b0b0f28aaf3e270825fb509b4606c34008a637b07bbc92e4b0191486b875a668
MD5 feefe410960a6f223455bc4828d32837
BLAKE2b-256 6cf4b745f39126f6c4aaaf1974b6308aec522a16346b3e442d856b256dfb7d39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pychisel-0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ad9c70a11e30e6a789d5de178b5520ebb948d34089ec23d53093447ae48f92
MD5 158601006055fdc0d25eec9d15c71b96
BLAKE2b-256 ed56ffad7cc59c09f169bf00e96a4ef0a5464ba98a3e556eb0fde35871971741

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