A lightweight data cleaning and preprocessing library for Python.
Project description
DataPrep-Lite
A lightweight and user-friendly Python library for common data cleaning and preprocessing tasks.
DataPrep-Lite simplifies your data preparation workflows by providing a suite of intuitive, configurable, and pipeline-able transformers, designed to work seamlessly with Pandas DataFrames and inspired by the scikit-learn API.
✨ Features
- 🐼 Pandas-Centric: Natively operates on Pandas DataFrames.
- 🤖 Scikit-learn Inspired API: Familiar
fit,transform, andfit_transformmethods. - 🧱 Modular & Reusable: Each operation is a distinct, configurable transformer.
- 🔗 Pipeline Ready: Easily chain multiple cleaning and preprocessing steps using the
Pipelineclass. - ⚙️ Configurable: Transformers offer parameters to customize their behavior for various scenarios.
- 🚀 Lightweight: Focuses on common, essential tasks without excessive dependencies.
📚 Table of Contents
🛠 Installation
From PyPI (Recommended)
DataPrep-Lite is published to PyPI, you can install it using pip:
pip install dataprep-lite
From Source
To install the latest development version directly from the GitHub repository:
git clone https://github.com/rahulkolekardev/DataPrep-Lite.git
cd DataPrep-Lite
pip install .
For development (editable install):
pip install -e .
# If you have development dependencies defined in setup.py or pyproject.toml:
# pip install -e ".[dev]"
Dependencies:
- Python 3.8+
- Pandas (>=1.3.0)
- NumPy (>=1.20.0)
- Scikit-learn (>=1.0.0)
🚀 Quick Start
Get up and running with DataPrep-Lite in minutes:
import pandas as pd
import numpy as np
# Import necessary components from dataprep_lite
from dataprep_lite.core import Pipeline
from dataprep_lite.cleaning import MeanImputer, DropDuplicates, TypeConverter
from dataprep_lite.preprocessing import OneHotEncoderWrapper, MinMaxScalerWrapper
# Sample DataFrame
data = {
'age': [25, 30, np.nan, 22, 30, 35],
'city': ['New York', 'London', 'Paris', 'New York', 'London', 'Tokyo'],
'experience_years': ['5', '10', '3', '2', '10', '12.5'], # String type
'salary': [70000, 90000, 65000, 50000, 90000, 110000.0]
}
df = pd.DataFrame(data)
print("Original DataFrame:\n", df)
# Define a preprocessing pipeline
pipeline = Pipeline([
('type_converter', TypeConverter(type_mapping={'experience_years': 'to_numeric'})),
('age_imputer', MeanImputer(columns_to_process=['age'])),
('duplicate_remover', DropDuplicates(subset=['age', 'city'], keep='first')),
('city_ohe', OneHotEncoderWrapper(columns_to_process=['city'], drop='first', sparse_output=False)),
('scaler', MinMaxScalerWrapper(columns_to_process=['age', 'experience_years', 'salary']))
])
# Apply the pipeline
df_cleaned = pipeline.fit_transform(df.copy()) # Use .copy() to preserve original
print("\nCleaned DataFrame:\n", df_cleaned.head())
print("\nCleaned DataFrame dtypes:\n", df_cleaned.dtypes)
🧩 Available Transformers
Core Components (dataprep_lite.core)
BaseTransformer: The abstract base class for all transformers. Enables creation of custom transformers compatible with the library's pipeline.Pipeline: Chains multiple transformer steps into a single workflow object.- Utility Functions: (e.g.,
identify_numeric_columns,identify_categorical_columns) for internal use and potentially for users.
Cleaning Transformers (dataprep_lite.cleaning)
- Missing Value Handlers:
MeanImputer(columns_to_process=None): Imputes with mean.MedianImputer(columns_to_process=None): Imputes with median.ModeImputer(columns_to_process=None): Imputes with mode.ConstantImputer(fill_value, columns_to_process=None): Imputes with a constant.DropMissing(axis=0, how='any', thresh=None, subset=None): Drops rows/columns with NaNs.
DropDuplicates(subset=None, keep='first', ignore_index=False): Removes duplicate rows.OutlierIQRHandler(columns_to_process=None, factor=1.5, action='cap'): Handles outliers using IQR (actioncan be'cap'or'remove_rows').TypeConverter(type_mapping, errors='raise'): Converts column data types (e.g.,{'col': 'int64'},{'col': 'to_numeric'}).BasicTextCleaner(columns_to_process=None, lowercase=True, strip_whitespace=True, remove_punctuation=True, ...): Performs basic text cleaning.
Preprocessing Transformers (dataprep_lite.preprocessing)
- Encoding:
OneHotEncoderWrapper(...): Wrapssklearn.preprocessing.OneHotEncoder.LabelEncoderWrapper(...): Wrapssklearn.preprocessing.LabelEncoder(column-wise).
- Scaling:
MinMaxScalerWrapper(...): Wrapssklearn.preprocessing.MinMaxScaler.StandardScalerWrapper(...): Wrapssklearn.preprocessing.StandardScaler.
KBinsDiscretizerWrapper(...): Bins continuous data. Wrapssklearn.preprocessing.KBinsDiscretizer.DatetimeFeatureCreator(...): Extracts features (year, month, day, hour, etc.) from datetime columns.
For detailed parameters of each transformer, please refer to their respective docstrings or the source code.
📋 Usage Examples
Basic Pipeline
from dataprep_lite.core import Pipeline
from dataprep_lite.cleaning import MedianImputer, DropDuplicates
from dataprep_lite.preprocessing import StandardScalerWrapper
# ... (assuming df is your DataFrame)
pipeline = Pipeline([
('imputer', MedianImputer(columns_to_process=['feature1', 'feature2'])),
('duplicates', DropDuplicates()),
('scaler', StandardScalerWrapper()) # Applies to all numeric columns by default
])
df_processed = pipeline.fit_transform(df.copy())
Using Individual Transformers
from dataprep_lite.cleaning import OutlierIQRHandler
# ... (assuming df is your DataFrame)
outlier_handler = OutlierIQRHandler(columns_to_process=['salary'], action='cap', factor=2.0)
df_no_outliers = outlier_handler.fit_transform(df.copy())
Custom Column Selection
Most transformers accept a columns_to_process parameter:
from dataprep_lite.cleaning import ModeImputer
# ... (assuming df is your DataFrame)
# Impute mode only for 'category_A' and 'category_B'
mode_imputer = ModeImputer(columns_to_process=['category_A', 'category_B'])
df_imputed = mode_imputer.fit_transform(df.copy())
If columns_to_process is not provided, transformers attempt to apply to suitable default columns (e.g., numeric columns for MeanImputer, text-like columns for BasicTextCleaner).
🙌 Contributing
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project (from
https://github.com/rahulkolekardev/DataPrep-Lite) - Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request (against
rahulkolekardev/DataPrep-Lite:main)
Please ensure your code adheres to common Python styling (e.g., PEP 8), and include tests for new features or bug fixes.
You can also contribute by:
- Reporting bugs or issues on the GitHub Issues page.
- Suggesting new features or enhancements.
- Improving documentation.
🗺️ Roadmap
- More advanced imputation techniques (e.g., KNNImputer wrapper).
- Additional text processing features (e.g., TF-IDF, stop word removal).
- Feature selection transformers (e.g., variance threshold, correlation-based).
- Enhanced reporting and logging capabilities for applied transformations.
- More robust handling of mixed-type columns in various transformers.
- Comprehensive Sphinx documentation hosted on ReadTheDocs.
- More extensive examples and tutorials.
- Integration with other data science ecosystem tools.
See the open issues for a full list of proposed features (and known issues).
📜 License
Distributed under the MIT License. See LICENSE file for more information.
(You will need to create a LICENSE file in your repository, typically with the MIT License text).
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
🙏 Acknowledgements
- Inspired by the ease of use and design patterns of scikit-learn.
- Built upon the power of Pandas and NumPy.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dataprep_lite-1.0.3.tar.gz.
File metadata
- Download URL: dataprep_lite-1.0.3.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1eaed4a46230f7214ef57155694367d75dbe721d59042eb3c3b8103531930fd6
|
|
| MD5 |
33e2a98e8a9ef1f51ff09e4c0d349f8b
|
|
| BLAKE2b-256 |
4a5bb1d949a657599f69306ee950e294578dda68d2cdaf04c4484ae6bac380b8
|
File details
Details for the file dataprep_lite-1.0.3-py3-none-any.whl.
File metadata
- Download URL: dataprep_lite-1.0.3-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b5e1be4e59595d875dc5b50d48e75cb59216fa05e753669c0649f54ebffe727
|
|
| MD5 |
123a998c52b8c9c774adbf067606298f
|
|
| BLAKE2b-256 |
8be44b12d3e4ac8e2775b04a2471497d089b1970559c8ba8bb3d53bfa469c950
|