readme
In [1]:
Copied!
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
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
[2022-12-02 14:18:09][datar][WARNING] Builtin name "filter" has been masked by datar.
In [2]:
Copied!
df = tibble(
x=range(4),
y=['zero', 'one', 'two', 'three']
)
print(df >> mutate(z=f.x))
df = tibble(
x=range(4),
y=['zero', 'one', 'two', 'three']
)
print(df >> mutate(z=f.x))
x y z <int64> <object> <int64> 0 0 zero 0 1 1 one 1 2 2 two 2 3 3 three 3
In [3]:
Copied!
print(df >> mutate(z=if_else(f.x>1, 1, 0)))
print(df >> mutate(z=if_else(f.x>1, 1, 0)))
x y z <int64> <object> <float64> 0 0 zero 0.0 1 1 one 0.0 2 2 two 1.0 3 3 three 1.0
In [4]:
Copied!
print(df >> filter(f.x>1))
print(df >> filter(f.x>1))
x y <int64> <object> 2 2 two 3 3 three
In [5]:
Copied!
print(df >> mutate(z=if_else(f.x>1, 1, 0)) >> filter(f.z==1))
print(df >> mutate(z=if_else(f.x>1, 1, 0)) >> filter(f.z==1))
x y z <int64> <object> <float64> 2 2 two 1.0 3 3 three 1.0
In [8]:
Copied!
# works with plotnine
import numpy
from datar.base import sin, pi
from datar.tibble import tibble
from datar.dplyr import mutate, if_else
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)
)
# works with plotnine
import numpy
from datar.base import sin, pi
from datar.tibble import tibble
from datar.dplyr import mutate, if_else
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)
)
Out[8]:
<ggplot: (8749008935172)>
In [9]:
Copied!
# very easy to integrate with other libraries
# for example: klib
import klib
from pipda import register_verb
from datar import f
from datar.data import iris
from datar.dplyr import pull
dist_plot = register_verb(func=klib.dist_plot)
iris >> pull(f.Sepal_Length) >> dist_plot()
# very easy to integrate with other libraries
# for example: klib
import klib
from pipda import register_verb
from datar import f
from datar.data import iris
from datar.dplyr import pull
dist_plot = register_verb(func=klib.dist_plot)
iris >> pull(f.Sepal_Length) >> dist_plot()
Out[9]:
<AxesSubplot:xlabel='Sepal_Length', ylabel='Density'>
In [ ]:
Copied!