It works well below, but
df['flag']=df['current'].apply(lambdax:1 if x>=5000 else0)
If you change it to the following, you will get an error.
df['flag']=df['current'].apply(lambdax:1 if x>=df['current2'] else0)
Error Message
ValueError: The truth value of a series is amazing. Use a.empty, a.bool(), a.item(), a.any() or a.all().
If you want to use apply
in more than one column, you must apply it to DataFrame instead of Series.
df['flag'] = df.apply (lambdax:1 if x.current>=x.current2else0,axis=1)
But let's use Pandas' vector operation for calculations like the question
df['flag']=(df['current']>=df['current2']).astype(int)
© 2024 OneMinuteCode. All rights reserved.