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"]
    }
}

⚙️ Configuration

danda is configurable, allowing you to control how cleaning and type detection behave. Every DataFrame has its own configuration, making it easy to customize behavior for different datasets.

import pandas as pd
import danda

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

# Disable numeric detection
df.dg.config.types.numeric_enabled = False

# Be more strict when detecting categories
df.dg.config.types.category_threshold = 0.05

# Preserve the original index when removing duplicates
df.dg.config.cleaning.remove_duplicates_ignore_index = False

df = df.dg.optimize()

You can inspect the current configuration at any time:

print(df.dg.config.show())

which produces output similar to:

TypeConfig
==========

Numeric Detection
-----------------

numeric_enabled                    : True
    Default     : True
    Description : Enable automatic detection and conversion of numeric columns.

numeric_threshold                  : 0.95
    Default     : 0.95
    Description : Minimum fraction of non-null values that must be successfully
                  converted to numeric before the column is considered numeric.

For a complete list of configuration options and examples, see the Configuration Guide.


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.2a2.tar.gz (17.5 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.2a2-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: danda-0.1.2a2.tar.gz
  • Upload date:
  • Size: 17.5 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.2a2.tar.gz
Algorithm Hash digest
SHA256 79f407d3c01d39f90afff0aee781343164ba51eec7874b235627bf325579d662
MD5 fa6fe175626af9e0968703cb2269f6e2
BLAKE2b-256 8d216f2eda002a57af9a9602aa57e5cda43d1bf51a856bebeef90ca978f3f098

See more details on using hashes here.

File details

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

File metadata

  • Download URL: danda-0.1.2a2-py3-none-any.whl
  • Upload date:
  • Size: 23.1 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.2a2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b1ea5db5ec4b4b2258f6b9f838c3a8085e700d3bf54bd8687e94e519c921fe8
MD5 d19446d5342f16596d8238407ba36bb9
BLAKE2b-256 051d721b3856e6cc8045a62b99033071220cb728a612e8cc9aa2df8ed490ba6c

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