Port of dplyr and other related R packages in python, using pipda.
Project description
datar
Port of dplyr and other related R packages in python, using pipda.
Documentation | Reference Maps | Notebook Examples | API | Blog
Unlike other similar packages in python that just mimic the piping syntax, datar follows the API designs from the original packages as much as possible, and is tested thoroughly with the cases from the original packages. So that minimal effort is needed for those who are familar with those R packages to transition to python.
Installtion
pip install -U datar
datar requires python 3.7.1+ and is backended by pandas (1.2+).
Example usage
from datar import f
from datar.dplyr import mutate, filter, if_else
from datar.tibble import tibble
# or
# from datar.all import f, mutate, filter, if_else, tibble
df = tibble(
x=range(4),
y=['zero', 'one', 'two', 'three']
)
df >> mutate(z=f.x)
"""# output
x y z
<int64> <object> <int64>
0 0 zero 0
1 1 one 1
2 2 two 2
3 3 three 3
"""
df >> mutate(z=if_else(f.x>1, 1, 0))
"""# output:
x y z
<int64> <object> <int64>
0 0 zero 0
1 1 one 0
2 2 two 1
3 3 three 1
"""
df >> filter(f.x>1)
"""# output:
x y
<int64> <object>
0 2 two
1 3 three
"""
df >> mutate(z=if_else(f.x>1, 1, 0)) >> filter(f.z==1)
"""# output:
x y z
<int64> <object> <int64>
0 2 two 1
1 3 three 1
"""
# works with plotnine
# example grabbed from https://github.com/has2k1/plydata
import numpy
from datar.base import sin, pi
from plotnine import ggplot, aes, geom_line, theme_classic
df = tibble(x=numpy.linspace(0, 2*pi, 500))
(df >>
mutate(y=sin(f.x), sign=if_else(f.y>=0, "positive", "negative")) >>
ggplot(aes(x='x', y='y')) +
theme_classic() +
geom_line(aes(color='sign'), size=1.2))
# easy to integrate with other libraries
# for example: klib
import klib
from pipda import register_verb
from datar.datasets import iris
from datar.dplyr import pull
dist_plot = register_verb(func=klib.dist_plot)
iris >> pull(f.Sepal_Length) >> dist_plot()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datar-0.4.4.tar.gz.
File metadata
- Download URL: datar-0.4.4.tar.gz
- Upload date:
- Size: 10.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1039-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cb201e3e00c2e5259c2d8307f3b2fea20c5ac37e1b125189ba68608779f2c01
|
|
| MD5 |
1d597d123ad249c00ae2723649b73bc5
|
|
| BLAKE2b-256 |
0a0bea96ba57f180fd594f0cf365959c6052dbf11b334601a53afba4537785bc
|
File details
Details for the file datar-0.4.4-py3-none-any.whl.
File metadata
- Download URL: datar-0.4.4-py3-none-any.whl
- Upload date:
- Size: 10.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1039-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d943ec553f83dec2e1a24842f1d735fc2f7e4cd2f0a3847b4a630e0efd6c869
|
|
| MD5 |
b6da473b97ea44a59ad18a576c444c3b
|
|
| BLAKE2b-256 |
eda3834fe61befc56fead12eae641e14418f296bcb37322367ea60152cc33726
|