Intelligent data processing tools for Spanish datasets (encoding, dates, numbers).
Project description
Spanish Tools
Spanish Tools is a Python library specifically designed to simplify the loading of Spanish language datasets for processing purposes. It aids with fixing encoding issues, regional numeric formats (decimal comma), dates, and text normalization (accents, 'ñ') using just one function. It is built on top of pandas and is compatible with any pandas DataFrame.
🚀 Install
pip install spanish_tools
Import
import spanish_tools as spa
Load Data and apply cleaning automatically
df = spa.load_data("sales_2024.xlsx")
For a more detailed walkthrough, continue reading.
⚡ Detailed walkthrough
import spanish_tools as spa
# 1. Load Data (Universal: CSV, Excel, etc.)
# This works for .csv, .xls, and .xlsx automatically.
# - Sets Spanish defaults (dec=',', sep=';') for CSVs.
# - Cleans headers to snake_case and removes any spanish special character such as 'ñ', 'á', 'é', 'í', 'ó', 'ú', 'ü'.
# - In case of encoding issues, it applyes an automatic fix to encoding (mojibake) in all text columns.
df = spa.load_data("sales_2024.xlsx")
# You can still pass pandas arguments:
df_csv = spa.load_data(
"sales_old.csv",
encoding="latin1",
parse_dates=["fecha"]
)
# 2. Clean Text (Explicit)
# This will clean the content of specific columns (removes accents, standardizes spaces, lowercases)
df = spa.clean_text(df, fields=["comments", "city"])
# 3. Clean Text (All)
# Or clean the entire DataFrame
df = spa.clean_text(df, fields="all", remove_accents=True)
print(df.head())
# Columns: 'fecha', 'ciudad' (snake_case headers)
# Content: 'malaga' (clean text)
✨ Key Features
- Universal Loader:
load_datahandles CSV and Excel files seamlessly. - Auto-Cleaning: Automatically fixes mojibake (encoding errors) and normalizes headers upon loading.
- "Pandas-Native" UX: Intuitive functions that integrate naturally into your workflow.
📚 API Reference
1. Loading and Processing (spanish_tools.core)
spa.load_data
Universal loader for CSV, Excel, ODS, XML, and Clipboard. Wraps pandas and applies automatic Spanish-focused cleaning.
def load_data(
ruta_archivo: str,
separador: str = ';',
**kwargs
) -> Optional[pd.DataFrame]
Supported Formats:
- CSV (
.csv): Auto-configured for Spanish standards (;,,). - Excel (
.xls,.xlsx): Standard Excel files. - OpenDocument (
.ods): Common in Public Administration. - XML (
.xml): Generic XML parsing. - Clipboard: Use
spa.load_data("clipboard")to load copied data.
Useful Pandas Arguments (**kwargs)
You can customize the loading by passing any standard pandas arguments:
| Argument | Description | Example |
|---|---|---|
sheet_name |
(Excel/ODS) specific sheet to load. | sheet_name='DataV1' |
encoding |
(CSV) Fixes strange characters. | encoding='latin1' |
parse_dates |
Automatically converts columns to datetime. | parse_dates=['date'] |
dtype |
Forces data type. | dtype={'dni': str} |
spa.clean_text
Cleans the text content of a loaded DataFrame.
def clean_text(
df: pd.DataFrame,
fields: List[str] | str,
remove_accents: bool = True,
**kwargs
) -> pd.DataFrame
- fields: Columns to clean. Can be a list of names
['col_a']or"all"for the entire DataFrame. - remove_accents: If
True(default), removes accents ('á' -> 'a') and normalizes 'ñ'. - kwargs: Included for potential future extensions, currently ignored.
2. Normalization
clean_header
Converts text to snake_case format, ideal for variable or column names.
import spanish_tools as spa
print(spa.clean_header("Creation Year (2024)"))
# Output: "creation_year_2024"
3. Text Cleaning
clean_string
Atomic cleaning for a text string. Removes unnecessary punctuation, extra spaces, and optionally accents.
import spanish_tools as spa
text = " HELLO WORLD! "
print(spa.clean_string(text))
# Output: "hello world"
🤝 Contributing
Contributions are welcome! If you find a bug or have an idea for a new feature:
- Fork the repository.
- Create a branch for your feature (
git checkout -b feature/new-feature). - Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/new-feature). - Open a Pull Request.
📄 License
This project is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
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 spanish_tools-0.1.1.tar.gz.
File metadata
- Download URL: spanish_tools-0.1.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93d8d977125d5036baf51d6d27f3114637282372ccb2fd8e59e2ee1204bb0665
|
|
| MD5 |
da0417ff2f4163e991bad7e8138ee39d
|
|
| BLAKE2b-256 |
edebeb0ffe79e3185ba62bacbb1e742c3417e4038e24d5be5a92ebdf5d828e0e
|
Provenance
The following attestation bundles were made for spanish_tools-0.1.1.tar.gz:
Publisher:
publish.yml on AleLoredo/spanish-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spanish_tools-0.1.1.tar.gz -
Subject digest:
93d8d977125d5036baf51d6d27f3114637282372ccb2fd8e59e2ee1204bb0665 - Sigstore transparency entry: 830754597
- Sigstore integration time:
-
Permalink:
AleLoredo/spanish-tools@645db74733a3bdad60f2522e13e0a7c0899724a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AleLoredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@645db74733a3bdad60f2522e13e0a7c0899724a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file spanish_tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spanish_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
196e4897ed5c0b8a05a973f51f0521ed76da91f110bf0985e449707d21af9228
|
|
| MD5 |
6d69d7fd4bd9ab8fe8ff2bf7c55a0901
|
|
| BLAKE2b-256 |
e673b2a060b1e6a6912d816f1f63406a8a488619a8ef3518689ea2349e969cec
|
Provenance
The following attestation bundles were made for spanish_tools-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on AleLoredo/spanish-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spanish_tools-0.1.1-py3-none-any.whl -
Subject digest:
196e4897ed5c0b8a05a973f51f0521ed76da91f110bf0985e449707d21af9228 - Sigstore transparency entry: 830754619
- Sigstore integration time:
-
Permalink:
AleLoredo/spanish-tools@645db74733a3bdad60f2522e13e0a7c0899724a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AleLoredo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@645db74733a3bdad60f2522e13e0a7c0899724a5 -
Trigger Event:
push
-
Statement type: