Skip to main content

Automatically prepare pandas DataFrames for analysis.

Project description

danda

Stop writing the same pandas preprocessing code over and over.

Automatically clean and optimize pandas DataFrames with one line of code.

danda is a lightweight extension for pandas that prepares messy data for analysis by automatically cleaning, converting data types, and reducing memory usage.

Instead of writing dozens of lines of preprocessing code, simply do:

clean_df = df.dg.clean().dg.optimize()

Why danda?

Every data scientist has written code like this:

df = pd.read_csv("sales.csv")

df = df.dropna(how="all")
df = df.dropna(axis=1, how="all")
df = df.drop_duplicates()

df["created_at"] = pd.to_datetime(df["created_at"])
df["active"] = df["active"].astype(bool)
df["country"] = df["country"].astype("category")
df["price"] = pd.to_numeric(df["price"])

With danda, all of that becomes:

df = pd.read_csv("sales.csv")

df = df.dg.clean().dg.optimize()

Features

🧹 Data cleaning

Automatically:

  • Remove empty rows
  • Remove empty columns
  • Remove duplicate rows
  • Strip leading/trailing whitespace

Example:

Before After
" John " "John"
" Alice" "Alice"
"Bob " "Bob"

📅 Automatic type detection

Automatically converts string columns to their appropriate pandas dtypes.

Boolean

"True"
"False"
"0"
"1"
0
1

boolean

Datetime

2024-01-01
2024/01/01
2024-01-01T12:30:00
Jan 1, 2024

datetime64[ns]

Numeric

"10"
"25"
"3.14"

int64 / float64

Category

Low-cardinality columns are automatically converted to pandas category dtype to reduce memory usage.

Example:

Country

Germany
France
Germany
Germany
France

category

📉 Memory optimization

Optimizing dtypes can dramatically reduce memory usage.

before.dg.compare_memory(after)

Example:

Before : 95 MB
After  : 21 MB

Saved : 74 MB (77.9%)

📄 Cleaning reports

Every operation produces a report describing what happened.

optimized.dg.report

Example:

{
    "clean": {
        "EmptyRowsPlugin":
            "Number of deleted rows: 15",

        "EmptyColumnsPlugin":
            "Number of deleted columns: 2",

        "DropDuplicates":
            "Number of deleted rows: 31"
    },

    "optimize": {
        "BooleanTypePlugin":
            ["active"],

        "DateTimeTypePlugin":
            ["created_at"],

        "NumericTypePlugin":
            ["price"],

        "CategoryTypePlugin":
            ["country"]
    }
}

Installation

pip install danda

Quick Start

import pandas as pd
import danda

df = pd.read_csv("employees.csv")

clean = df.dg.clean()

optimized = clean.dg.optimize()

print(optimized.dg.report)

print(clean.dg.compare_memory(optimized))

Pandas Accessor

danda integrates directly into pandas using a custom accessor.

df.dg.clean()

df.dg.optimize()

df.dg.report

df.dg.compare_memory(other_df)

No new DataFrame class. No wrapper objects.

Just pandas.


Philosophy

danda follows a simple principle:

Prepare data for analysis automatically while preserving the familiar pandas workflow.

The library is designed to feel like a natural extension of pandas rather than a replacement.


Roadmap

Planned features include:

  • Read functions (danda.read_csv(), read_excel(), read_parquet())
  • Missing value normalization
  • Integer downcasting
  • Float optimization
  • Automatic ID detection
  • Data validation
  • Dataset profiling
  • Configurable plugin pipeline
  • Custom plugins

Plugin Architecture

danda is built around a plugin system.

Current plugins include:

  • EmptyRowsPlugin
  • EmptyColumnsPlugin
  • DropDuplicatesPlugin
  • EmptySpacesPlugin
  • BooleanTypePlugin
  • DateTimeTypePlugin
  • NumericTypePlugin
  • CategoryTypePlugin

Creating your own plugins is straightforward, allowing you to customize the cleaning pipeline for your own datasets.


Contributing

Contributions, feature requests, and bug reports are welcome!

If you have an idea that makes data cleaning easier, feel free to open an issue or submit a pull request.

Normalize missing values

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

danda-0.1.2a1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

danda-0.1.2a1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file danda-0.1.2a1.tar.gz.

File metadata

  • Download URL: danda-0.1.2a1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for danda-0.1.2a1.tar.gz
Algorithm Hash digest
SHA256 46c91ff8cfd45aa652ed678b3762c8a3285597e7691abeb17c68e19573f8f7be
MD5 15e67914b9c8a8412a5216c4544bd6c8
BLAKE2b-256 c994a2779eae88eace6669c6b0229e8fcf0ebbdf8e7f91238cb75fdc2823d7f0

See more details on using hashes here.

File details

Details for the file danda-0.1.2a1-py3-none-any.whl.

File metadata

  • Download URL: danda-0.1.2a1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for danda-0.1.2a1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c1552aa89b1ed1d2429798c2b61acbcaba17b7c0e0a155fba46792de4c02b07
MD5 0591df4347fdea155ebf1d8127016aa0
BLAKE2b-256 cd04bfc5fe39b077ef41aa48c1cfe0410dce8644c6e3c5f8d9cb0e9d72d2358c

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