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.3.1.tar.gz (4.9 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.3.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pychisel-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9cf8efc861c3d387794e4de26af68eab4df5727cefd5a5b70ed5b3966c2f06a6
MD5 383d9b3232c7495499a209479965f30f
BLAKE2b-256 2fc6f94f98e31231db3a5c75c4d4568ffa01982bc3314452b268c8c999e3660d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pychisel-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3ab3ef457eedb095dfe9cb3df99d078f161cd59eb09f3f3a3792145594354cd
MD5 b41509f590fdb538f28c2ab079671023
BLAKE2b-256 53530e58e1f4cb7769db3f69ef167904063eeb09fbef647843462197cacb8a6f

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