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 prepares DataFrames for analysis by performing safe, deterministic cleaning, type inference, and memory optimization while preserving the meaning of the data.

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.


Filling Missing Values

danda can automatically fill missing values after your DataFrame has been cleaned and optimized.

Unlike cleaning operations (such as removing empty rows or converting data types), filling missing values changes the data. For this reason, imputation is disabled by default and must be explicitly enabled.

Supported Strategies

By default, danda selects a strategy based on the column data type:

Data Type Default Strategy
Numeric Median
Boolean Mode
Category Mode
Text Mode
Datetime Forward fill

These strategies can be customized through the configuration.

Usage

import danda

df = (
    pd.read_csv("data.csv")
      .dg.clean()
      .dg.optimize()
      .dg.impute()
)

Enable imputation:

df.dg.config.imputation.enabled = True

Customize strategies:

df.dg.config.imputation.numeric_strategy = "mean"
df.dg.config.imputation.category_strategy = "constant"
df.dg.config.imputation.datetime_strategy = "bfill"

Report

After imputation, danda records which columns were filled and the strategy that was used.

Example:

Filled missing values:
- Age: median (12)
- Salary: mean (4)
- Country: mode (8)
- Date: ffill (2)

Learn More

For a complete description of the available strategies, configuration options, and implementation details, see Imputation 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.2a3.tar.gz (24.6 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.2a3-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: danda-0.1.2a3.tar.gz
  • Upload date:
  • Size: 24.6 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.2a3.tar.gz
Algorithm Hash digest
SHA256 f4e28b88e2b8d9e61e8fb994b52b46da0aab68dd8a0fa1587314c4730a027f48
MD5 f527679aa84a27f49df1643f5c704e6e
BLAKE2b-256 cf2be2e978e088562746955eb4ce5944d14a59f3f4a6a203b931e5ba05f88d03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: danda-0.1.2a3-py3-none-any.whl
  • Upload date:
  • Size: 36.5 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.2a3-py3-none-any.whl
Algorithm Hash digest
SHA256 f4b1f944035d5adcc9dee0bd89c6858f29c9254875de4237fa46043d8a772565
MD5 c35780540c100cf5bf4a9e126257dbf1
BLAKE2b-256 04289ff4dfd9e5fae19832feebf67dc21fe49900af0da81bacb4742e585eade2

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