A data cleaning library for Pandas and Polars DataFrames with a simple, chainable API.
Project description
Sanex
Sanex is a powerful and intuitive data cleaning library for Python, designed to work seamlessly with both pandas and polars DataFrames. With a fluent, chainable API, Sanex makes the process of cleaning and preparing your data not just easy, but enjoyable.
🚀 Key Features
- Fluent, Chainable API: Clean your data in a single, readable chain of commands.
- Dual Backend Support: Works effortlessly with both pandas and polars DataFrames.
- Comprehensive Cleaning Functions: From column name standardization to outlier handling, Sanex has you covered.
- Extensible: Easily add your own cleaning functions to the pipeline.
- Lightweight and Performant: Designed to be fast and efficient.
📦 Installation
Install Sanex easily with pip:
pip install sanex
⚡ Quick Start
Here's a quick example of how to use Sanex to clean a DataFrame:
import pandas as pd
from sanex import Sanex
# Create a sample DataFrame
data = {
'First Name': [' John ', 'Jane', ' Peter', 'JOHN'],
'Last Name': ['Smith', 'Doe', 'Jones', 'Smith'],
'Age': [28, 34, 22, 28],
'Salary': [70000, 80000, 65000, 70000],
'is_active': ['True', 'False', 'true', 'TRUE']
}
df = pd.DataFrame(data)
# Clean the data with Sanex
clean_df = (
Sanex(df)
.clean_column_names()
.remove_whitespace()
.remove_duplicates()
.standardize_booleans()
.to_df()
)
print(clean_df)
📖 API Reference
The Sanex class provides a variety of methods for data cleaning. All methods (except to_df) are chainable, returning the Sanex instance.
Initialization
Sanex(df): Initializes the cleaner with a pandas or polars DataFrame.
Column Name Cleaning
-
.clean_column_names(case='snake'): Cleans and standardizes all column names to a specified case.case(str): The target case. Options:'snake','camel','pascal','kebab','title','lower','screaming_snake'.
-
.snakecase(): Converts column names tosnake_case. -
.camelcase(): Converts column names tocamelCase. -
.pascalcase(): Converts column names toPascalCase. -
.kebabcase(): Converts column names tokebab-case. -
.titlecase(): Converts column names toTitle Case. -
.lowercase(): Converts column names tolowercase. -
.screaming_snakecase(): Converts column names toSCREAMING_SNAKE_CASE.
Data Deduplication
.remove_duplicates(): Removes duplicate rows from the DataFrame.
Missing Data Handling
-
.fill_missing(value=0, subset=None): Fills missing values.value: The value to fill missing entries with.subset(list): A list of columns to fill. Defaults to all columns.
-
.drop_missing(how='any', thresh=None, subset=None, axis='rows'): Drops rows or columns with missing values.how(str):'any'or'all'.thresh(int): The number of non-NA values required to keep a row/column.subset(list): Columns to consider.axis(str):'rows'or'columns'.
Whitespace and Text Manipulation
.remove_whitespace(): Removes leading and trailing whitespace from all string columns..replace_text(to_replace, value, subset=None): Replaces text in string columns.to_replace(str): The text to find.value(str): The text to replace with.subset(list): Columns to apply the replacement to.
Column Management
.drop_single_value_columns(): Drops columns that have only one unique value.
Outlier Handling
.handle_outliers(method='iqr', factor=1.5, subset=None): A general method that can be configured to cap or remove outliers..cap_outliers(method='iqr', factor=1.5, subset=None): Caps outliers at a specified threshold..remove_outliers(method='iqr', factor=1.5, subset=None): Removes rows containing outliers.method(str):'iqr'(Interquartile Range) or'zscore'.factor(float): The multiplier for the chosen method to determine the outlier threshold.subset(list): Columns to process. Defaults to all numeric columns.
Data Standardization
.standardize_booleans(true_values=None, false_values=None, subset=None): Converts boolean-like values into actual booleans.true_values(list): A list of strings to be consideredTrue.false_values(list): A list of strings to be consideredFalse.subset(list): Columns to standardize.
Final Output
.to_df(): Returns the cleaned pandas or polars DataFrame.
🤝 Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for bugs, feature requests, or suggestions.
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/YourFeature). - Open a pull request.
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
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 sanex-0.1.1.tar.gz.
File metadata
- Download URL: sanex-0.1.1.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bf3bf2048f5b332fdc35a89e7fb9c0115c5f1ae966cc082bcebbf7b9a8053ce
|
|
| MD5 |
a37d54d70b97917591c67bf477d0c835
|
|
| BLAKE2b-256 |
43728bcb864d01c5cc78ee4832730a4b8cf555490f0a18a17e7a84a58ffb59cc
|
File details
Details for the file sanex-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sanex-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c99afe9cc31d57ded85f722e71aed5ff272cf6625aea3fcb44b609dcd791ae66
|
|
| MD5 |
47b6c82343ff721b3e5303a7db50517f
|
|
| BLAKE2b-256 |
550ddf7085a7623adb85454e98f56700396ab050038b1e1f1c973b97c4403846
|