Skip to main content

Intelligent data processing tools for Spanish datasets (encoding, dates, numbers).

Project description

Spanish Tools

PyPI version Python Version License: MIT

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_data handles 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:

  1. Fork the repository.
  2. Create a branch for your feature (git checkout -b feature/new-feature).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature/new-feature).
  5. Open a Pull Request.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more 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

spanish_tools-0.1.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spanish_tools-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for spanish_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 93d8d977125d5036baf51d6d27f3114637282372ccb2fd8e59e2ee1204bb0665
MD5 da0417ff2f4163e991bad7e8138ee39d
BLAKE2b-256 edebeb0ffe79e3185ba62bacbb1e742c3417e4038e24d5be5a92ebdf5d828e0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_tools-0.1.1.tar.gz:

Publisher: publish.yml on AleLoredo/spanish-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for spanish_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 196e4897ed5c0b8a05a973f51f0521ed76da91f110bf0985e449707d21af9228
MD5 6d69d7fd4bd9ab8fe8ff2bf7c55a0901
BLAKE2b-256 e673b2a060b1e6a6912d816f1f63406a8a488619a8ef3518689ea2349e969cec

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_tools-0.1.1-py3-none-any.whl:

Publisher: publish.yml on AleLoredo/spanish-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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