siuba
siuba copied to clipboard
if else statement in mutate function
Hi Michael,
Could we use if else statement in mutate function? I found this part is empty in the document.
https://siuba.readthedocs.io/en/latest/api_table_core/05_mutate.html#With-if_else-and-case_when
Thanks
You can!
from siuba import *
from siuba.data import mtcars
(
mtcars
>> mutate(hp_category = if_else(_.hp >= 150, "high hp", "low hp"))
)
I've added a page in the siuba guide showing if_else used outside and inside of verbs :)
https://siuba.org/guide/ops-case-when.html