A small package for big slicing.
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
$
pip install slicerslicer [alpha]
(Equal Contribution) Samuel Jenkins & Harsha Nori & Scott Lundberg
slicer wraps tensor-like objects and provides a uniform slicing interface via __getitem__.
It supports many data types including:
numpy | pandas | scipy | pytorch | list | tuple | dict
And enables upgraded slicing functionality on its objects:
# Handles non-integer indexes for slicing.
S(df)[:, ["Age", "Income"]]
# Handles nested slicing in one call.
S(nested_list)[..., :5]
It can also simultaneously slice many objects at once:
# Gets first elements of both objects.
S(first=df, second=ar)[0, :]
This package has 0 dependencies. Not even one.
Installation
Python 3.6+ | Linux, Mac, Windows
pip install slicer
Getting Started
Basic anonymous slicing:
from slicer import Slicer as S
li = [[1, 2, 3], [4, 5, 6]]
S(li)[:, 0:2].o
# [[1, 2], [4, 5]]
di = {'x': [1, 2, 3], 'y': [4, 5, 6]}
S(di)[:, 0:2].o
# {'x': [1, 2], 'y': [4, 5]}
Basic named slicing:
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, 3], 'B': [2, 4]})
ar = np.array([[5, 6], [7, 8]])
sliced = S(first=df, second=ar)[0, :]
sliced.first
# A 1
# B 2
# Name: 0, dtype: int64
sliced.second
# array([5, 6])