Skip to main content

Helper functions for pandas data analysis, inspired by R

Project description

baribal 🐻

Build Status PyPI version PyPI downloads Coverage License Python Versions Code style: ruff

A Python package extending pandas and polars with helper functions for simpler exploratory data analysis and data wrangling, inspired by R's tidyverse packages.

Why Baribal?

While pandas and polars are incredibly powerful, some R functions like glimpse(), tabyl(), or clean_names() make data exploration and manipulation particularly smooth. Baribal brings these functionalities to Python, helping you to:

  • Get quick, insightful overviews of your DataFrames
  • Perform common data cleaning tasks with less code
  • Handle missing values more intuitively
  • Generate summary statistics with minimal effort
  • Optimize memory usage with smart type inference

Features

Core Functions

🔍 glimpse()

R-style enhanced DataFrame preview that works with both pandas and polars:

import pandas as pd
import baribal as bb

df = pd.DataFrame({
    'id': range(1, 6),
    'name': ['John Doe', 'Jane Smith', 'Bob Wilson', 'Alice Brown', 'Charlie Davis'],
    'age': [25, 30, 35, 28, 42],
    'score': [92.5, 88.0, None, 95.5, 90.0]
})

bb.glimpse(df)

Output:

Observations: 5
Variables: 4
DataFrame type: pandas
$ id    <int> 1, 2, 3, 4, 5
$ name  <chr> "John Doe", "Jane Smith", "Bob Wilson", "Alice Brown", "Charlie Davis"
$ age   <int> 25, 30, 35, 28, 42
$ score <num> 92.5, 88.0, NA, 95.5, 90.0

📊 tabyl()

Enhanced cross-tabulations with integrated statistics:

import baribal as bb

# Single variable frequency table
result, _ = bb.tabyl(df, 'category')

# Two-way cross-tabulation with chi-square statistics
result, stats = bb.tabyl(df, 'category', 'status')

Data Cleaning

🧹 clean_names()

Smart column name cleaning with multiple case styles:

import baribal as bb

df = pd.DataFrame({
    "First Name": [],
    "Last.Name": [],
    "Email@Address": [],
    "Phone #": []
})

# Snake case (default)
bb.clean_names(df)
# → columns become: ['first_name', 'last_name', 'email_address', 'phone']

# Camel case
bb.clean_names(df, case='camel')
# → columns become: ['firstName', 'lastName', 'emailAddress', 'phone']

# Pascal case
bb.clean_names(df, case='pascal')
# → columns become: ['FirstName', 'LastName', 'EmailAddress', 'Phone']

🔄 rename_all()

Batch rename columns using patterns:

import baribal as bb

# Using regex pattern
bb.rename_all(df, r'Col_(\d+)')  # Extracts numbers from column names

# Using case transformation
bb.rename_all(df, lambda x: x.lower())  # Convert all to lowercase

Analysis Tools

🔍 missing_summary()

Comprehensive missing values analysis:

import baribal as bb

summary = bb.missing_summary(df)
# Returns DataFrame with missing value statistics for each column

Installation

pip install baribal

Dependencies

  • Python >= 3.8
  • pandas >= 1.0.0
  • polars >= 0.20.0 (optional)
  • numpy
  • scipy

Development

This project uses modern Python development tools:

  • uv for fast, reliable package management
  • ruff for lightning-fast linting and formatting
  • pytest for testing

To set up the development environment:

make install

To run tests:

make test

Contributing

Contributions are welcome! Whether it's:

  • Suggesting new R-inspired features
  • Improving documentation
  • Adding test cases
  • Reporting bugs

Please check out our Contributing Guidelines for details on our git commit conventions and development process.

License

MIT License

Acknowledgments

Inspired by various R packages including:

  • dplyr
  • janitor
  • tibble
  • naniar

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

baribal-0.2.1.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

baribal-0.2.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file baribal-0.2.1.tar.gz.

File metadata

  • Download URL: baribal-0.2.1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for baribal-0.2.1.tar.gz
Algorithm Hash digest
SHA256 941bb0d92d2685d70216e45c550f93c293e35f77be38c52eb336b05f85efc201
MD5 e0f262bc0e08150538cd056d8485013f
BLAKE2b-256 8a716a9c272e66bb2f4ae2fcf66262a31ac67c605f5bb39105c8ab0ae1c8d2fa

See more details on using hashes here.

File details

Details for the file baribal-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: baribal-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for baribal-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7b31cac183c2d559bcbec3e4a069a16d70cc56dcc8c0663f1e78c4d71222386
MD5 bbab4a71d303c23285f9f55dd9a259b4
BLAKE2b-256 99298c73df91b5d1f2161fdfffa63a9b77b57c8c656c1a198c08c37fba52ee4d

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