coalesce

In [ ]:
coalesce(expr, *argv)

Returns the value of the first non-null expression in the list.

Parameters

Name Type Optional Description
expr
object
Expression.
argv
object
Infinite Number of Expressions.

Returns

str_sql : SQL expression.

Example

In [71]:
from verticapy import *
df = tablesample({"x": [0.8, -1, None, -2, None]}).to_vdf()
display(df)
123
x
Numeric(19,1)
10.8
2-1.0
3[null]
4-2.0
5[null]
Rows: 1-5 | Column: x | Type: numeric(19,1)
In [72]:
# Importing the stats module
import verticapy.stats as st

# Applying the coalesce function
df["coalesce_x"] = st.coalesce(df["x"],  666)
display(df)
123
x
Numeric(19,1)
123
coalesce_x
Numeric(19,1)
10.80.8
2-1.0-1.0
3[null]666.0
4-2.0-2.0
5[null]666.0
Rows: 1-5 | Columns: 2