Skip to content

Utilz

Build Status Coverage Status Python Versions Platforms

Convenient helper functions, decorators, and data analysis tools to make life easier with minimal dependencies:

pip install py-utilz

dplyr like data grammar:

from utilz import pipe
import utilz.dfverbs as _

out = pipe(
    df,
    _.rename({"weight (male, lbs)": "male", "weight (female, lbs)": "female"}),
    _.pivot_longer(columns=["male", "female"], into=("sex", "weight")),
    _.split("weight", ("min", "max"), sep="-"),
    _.pivot_longer(columns=["min", "max"], into=("stat", "weight")),
    _.astype({"weight": float}),
    _.groupby("genus", "sex"),
    _.mutate(weight="weight.mean()"),
    _.pivot_wider(column="sex", using="weight"),
    _.mutate(dimorphism="male / female")
)

More convenient (parallel) looping:

from utilz import mapcat

# Combine function results into a list, array, or dataframe
mapcat(myfunc, myiterable) 

# Syntactic sugar for joblib.Parallel
mapcat(myfunc, myiterable, n_jobs=4)

Useful decorators for data analysis:

from utilz import log, maybe

# Print the shape of args and outputs before and after execute
@log
def myfunc(args):
    return out

# Only run myfunc if results.csv doesn't eist
@maybe('results.csv')
def myfunc(args):
    return out

Checkout the overview page for more!