decode

In [ ]:
decode(expr, *argv)

Compares expression to each search value one by one.

Parameters

Name Type Optional Description
expr
object
❌
Expression.
argv
object
❌
Infinite Number of Expressions. The expression generated will look like:
even: CASE ... WHEN expr = argv[2 * i] THEN argv[2 * i + 1] ... END
odd : CASE ... WHEN expr = argv[2 * i] THEN argv[2 * i + 1] ... ELSE argv[n] END

Returns

str_sql : SQL expression.

Example

In [73]:
from verticapy import *
df = tablesample({"x": ['banana', 'apple', 'onion', 'potato']}).to_vdf()
display(df)
Abc
x
Varchar(6)
1banana
2apple
3onion
4potato
Rows: 1-4 | Column: x | Type: varchar(6)
In [74]:
# Importing the stats module
import verticapy.stats as st

# Applying the decode function
df["type_x"] = st.decode(df["x"],  
                         'banana', 'fruit',
                         'apple', 'fruit',
                         'vegetable')
display(df)
Abc
x
Varchar(6)
Abc
type_x
Varchar(9)
1bananafruit
2applefruit
3onionvegetable
4potatovegetable
Rows: 1-4 | Columns: 2