Код: Выделить всё
thedf = pd.DataFrame({'a':[10,20,0],'b':[9,16,15]})
thedf
a b
0 10 9
1 20 16
2 0 15
Код: Выделить всё
thedf.assign(division = lambda x: x['b']/x['a'] if x['a'] != 0 else 0)
Код: Выделить всё
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().Код: Выделить всё
a b division
0 10 9 0.9
1 20 16 0.8
2 0 15 0
п>
Подробнее здесь: https://stackoverflow.com/questions/787 ... ndas-chain