Skip to main content

viper

Simple, expressive pipeline syntax to transform and manipulate data with ease

Overview

viper is a Python package that provides a simple, expressive way to work with data. It allows you to easily manipulate and transform data using a pipeline syntax similar to that of dplyr.

Pipelining your DataFrame manipulation operations offers several benefits:

  • improved code readability (no need to 'comment the what')
  • no need to save intermediate dataframes
  • ability to chain a long sequence of operations in a single command
  • thinking of coding as a series of transformations between the input and the desired output can improve the design and make it less coupled

Docs

Complete documentation and reference are available on the package's site.

Quick Start

Installation:

pip install viper

Here is an example of how to use viper to analyze the famed mtcars dataset.

We want to find:

  • the average consumption, expressed in Miles/(US) gallon
  • the average power

Furthermore:

  • only consider those cars that weigh more than 2000lbs
  • group the results by the number of cylinders and number of gears
  • arrange in descending orders by the grouping variables
from viper.main import *
from viper.data import mtcars

pipeline(
    mtcars,
    rename(
        "hp = power",
        "mpg = consumption",
    ),
    mutate(
        consumption=lambda r: 1 / r["consumption"]
    ),
    filter(
        lambda r: r["wt"] > 2
    ),
    group_by("cyl", "gear"),
    summarize(
        "power = mean()",
        "consumption = mean()"
    ),
    arrange(
        "cyl desc",
        "gear desc"
    ),
)
#                power  consumption
# cyl gear
# 8   5     299.500000     0.064979
#     3     194.166667     0.068824
# 6   5     175.000000     0.050761
#     4     116.500000     0.050875
#     3     107.500000     0.050989
# 4   5      91.000000     0.038462
#     4      85.000000     0.041259
#     3      97.000000     0.046512

Here you can find more examples, particularly on joins.

Roadmap

The future development of the package will probably focus on:

  • adding pivot_longerand pivot_wider functions
  • adding more join_* functions

Contributions

You are welcome to contribute to the project or open issues if you have any ideas.

Release files for viper-test 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viper-test 0.0.1
File Size Uploaded
viper_test-0.0.1.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for viper-test 0.0.1
File Interpreter ABI Platform
viper_test-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / viper_test-0.0.1.tar.gz

Download URL viper_test-0.0.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6da2f37c227ca7bfa43267079ed988802f614359c407b6b8d32b4c07c39a2022
BLAKE2b-256 checksum
How to use checksums
d4bf4c914db66c566181077e4455d2e11150aee7e068a22aa91706412b67460c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / viper_test-0.0.1-py3-none-any.whl

Download URL viper_test-0.0.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
091c8eb4647deb2197fbeedb1f0be7fa346ddeb0b39250bb2b7e8ba09e758af4
BLAKE2b-256 checksum
How to use checksums
b74f4fe2c31b8d6291222b8a74b4e1dd33548ed8a2ae5bdb2deb8c09590e7ceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page