I am creating a series of calculations in my dataframe and have been using apply successfully, until the one example below. Can anyone explain why "transform" works in this instance but "apply" does not? Ive been doing operations of addition and subtraction with apply successfully, so the new aspect is the np.where.
It doesn't throw an error, it just returns NaNs for the columns.
None of the articles i can find address that apply should have this type of limitation. There is lots of information suggesting transform should be more limiting, namely by only being only to process a single column at a time, and being forced to return a quantity of values equal to the series length.
df['val'] = compiled.groupby(['category']).B.apply(lambda x : np.where(x > 0, x, 0))
df['val'] = compiled.groupby(['category']).B.transform(lambda x : np.where(x > 0, x, 0))