Using assign in Pandas 1.0 I would like to create a new flag column based on the following logic:
import numpy as np
import pandas as pd
df = pd.DataFrame({'val': [10, 2, 0, 1, 0.4, 2]})
df = df.assign(
    flag=lambda x: False if np.bool(x['val'] == 0) else True if np.bool(x['val'] < 0.5) else False
)
I expect:
df
   val    flag
0   10    False
1    2    False
2    0    False
3    1    False
4    0.4  True
5    2    False
Instead I get:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
I tried with np.where(), np.any(), np.all() but I do not get the expected result.
 
    