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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pychisel-0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 62291e48fc507a7edac7ed135e764b0f539a6cb2281331301a4b48181341f5d1
MD5 306a19df4077aa7ebb5dee60741b7aeb
BLAKE2b-256 172c916101101d490e2fb59f2ecca0bced12f265089cd42676afee9a0a92c328

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pychisel-0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7a4fe3adfc8e43a377adb1e0f398798f92cff5fbe1e0bf528f3a5d500249aa
MD5 429208cdf43f5b6eea796c13623b9b98
BLAKE2b-256 ff1d631b1b890bb4bc2e77c95f3778d9f92488355e33052f21611356aa1f8714

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