I want to set a virtual column to a calculation using another column in Vaex. I need to use an if statement inside this calculation. In general I want to call
df['calculation_col'] = log(df['original_col']) if df['original_col'] == 0 else -4
I then try to run the count function in Vaex:
hist = df.count(
binby='calculation_col',
limits=limits,
shape=binnum,
delay=True
)
When I try to execute this code I get the error ValueError: zero-size array to reduction operation minimum which has no identity
.
How can I use a conditional for a virtual column in Vaex?
Probably the most "vaex" way to do this would be to use where
:
import vaex
df = vaex.example()
# The syntax is where(condition, if satisfied, else)
df['calculated_col'] = df.func.where(df['x'] < 10, 0, -4)