Functional pipes in python like %>% from R's magritrr

后端 未结 14 2233
春和景丽
春和景丽 2020-11-29 16:17

In R (thanks to magritrr) you can now perform operations with a more functional piping syntax via %>%. This means that instead of coding this: <

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 16:43

    You can use sspipe library. It exposes two objects p and px. Similar to x %>% f(y,z), you can write x | p(f, y, z) and similar to x %>% .^2 you can write x | px**2.

    from sspipe import p, px
    from math import sqrt
    
    12 | p(sqrt) | px ** 2 | p(str)
    

提交回复
热议问题