Skip to main content

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.

Pypi Github Building Docs and API Codacy Codacy coverage

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
# to make sure dependencies to be up-to-date
# pip install -U varname pipda datar

datar requires python 3.7.1+ and is backended by pandas (1.3+).

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),  # or f[: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))

example

# easy to integrate with other libraries
# for example: klib
import klib
from datar.core.factory import verb_factory
from datar.datasets import iris
from datar.dplyr import pull

dist_plot = verb_factory(func=klib.dist_plot)
iris >> pull(f.Sepal_Length) >> dist_plot()

example

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

datar-0.6.3.tar.gz (10.2 MB view details)

Uploaded Source

Built Distribution

datar-0.6.3-py3-none-any.whl (10.3 MB view details)

Uploaded Python 3

File details

Details for the file datar-0.6.3.tar.gz.

File metadata

  • Download URL: datar-0.6.3.tar.gz
  • Upload date:
  • Size: 10.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for datar-0.6.3.tar.gz
Algorithm Hash digest
SHA256 dafff0e0953764b17325a56fb532797c65909b7d6a4377391ba4fa2d915fe27e
MD5 cd0106cc47b449893b1f832e496628e0
BLAKE2b-256 50b4ee11338bac84688252b18e8a418af156ab1b499ec27256839972325651ce

See more details on using hashes here.

Provenance

File details

Details for the file datar-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: datar-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for datar-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e60581cf0f2948513a253ae640ceb72063f846386f03aef17cea07aa048b445b
MD5 e2823e1cd1f3b0ee5f6d6dfb9bb8b932
BLAKE2b-256 169f16a857a9dcd077780e481880a250f610dfdf5fbc5edc70d40bd52e00ac6f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page