I have a DataFrame like this:
df = pd.DataFrame(columns=['count', 'color'])
For each row that has count > 0, I want to assign 'red' to color if
np.random.binomial(1,prob)==1
I know how to do it with a for loop.
I also know that, if there wasn't this condition, I could assign the red color without a for loop, in this way:
df.loc[df['count']>0, ['color']]='red'
Is it possible to have both the filter on count and the condition on prob without the for loop?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…