case_when¶
In [ ]:
case_when(*argv)
Returns the conditional statement of the input arguments.
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
argv | object | ❌ | Infinite Number of Expressions. The expression generated will look like: even: CASE ... WHEN argv[2 * i] THEN argv[2 * i + 1] ... END odd : CASE ... WHEN argv[2 * i] THEN argv[2 * i + 1] ... ELSE argv[n] END |
In [69]:
from verticapy import *
df = tablesample({"x": [0.8, -1, 0, -2, 0.5]}).to_vdf()
display(df)
In [70]:
# Importing the stats module
import verticapy.stats as st
# Applying the case_when function
df["x_pos"] = st.case_when(df["x"] > 0, 1,
df["x"] == 0, 0,
-1)
display(df)
