Q: Appling condition in lambda function in python I have a pandas data frame and creating new column out of existing column values with'-' separator
I am trying this below code its not working as expected.
data["{}_pid".format(granularity)] = data[config['compute_hierarchy'][granularity]].apply(lambda x: x.str.cat(sep='-') if x.granularity != None, axis=1 )

ex: if i have column value as a,b,c then new column value is a-b-c and if any column value is null then lambda function should not execute

A: "if" keyword "directly" (I'm being vague) in a lambda can only be part of a ternary operator.
So this lambda :
l1 = lambda x:  "yes" if x else "no"

is correct, while this one :
l2 = lambda x:  "yes" if x

is not.
If without else can be part of an expression in a list comprehension :
[print(a) for a in range(10) if a % 2]

