want to calculate C based on values of count, A and B
sample df:
| count | A | B | C |
|---|---|---|---|
| yes | 23 | 2 | nan |
| nan | 23 | 1 | nan |
| yes | 41 | 6 | nan |
result I want
| count | A | B | C |
|---|---|---|---|
| yes | 23 | 2 | 46 |
| nan | 23 | 1 | 0 |
| yes | 41 | 6 | 246 |
calculate C = A*B only when count value = yes otherwise C values =0 that is, it should skip nan values of count
Any help is appreciable
I am trying this
for ind, row in df.iterrows():
if df['count'] == 'yes':
df.loc[ ind, 'C'] =row['A'] *row['B']
else:
df.loc[ ind, 'C'] =0
But it's giving error : ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().