reshaped['cumq'] = reshaped.groupby(['trader', 'stock']).delta.cumsum()
reshaped.loc[reshaped.cumq == 0, '_spell'] = 1
reshaped['_spell'] = reshaped.groupby(['trader', 'stock'])['_spell'].cumsum()
reshaped['_spell'] = reshaped.groupby(['trader', 'stock'])['_spell'].bfill(
    ).fillna(0)
how to speed-up a very slow pandas apply function?