I wanted to create a new column of a dataframe based on existing columns, however I want it to be conditional on another existing column in my dataframe. The following code is not working. Does anyone know why?
if CV['keyword'] == 0:
CV['left out'] = (CV['Prediction Numerator'] - (CV['Rate'] *10000))/(CV['Prediction Denominator'] - 10000)
else:
CV['left out'] = (CV['Prediction Numerator'] - (CV['Rate'] *10000 * 10))/(CV['Prediction Denominator'] - (10000 * 10))
I'm getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\bwei\Downloads\WinPython-64bit-2.7.9.4\python-2.7.9.amd64\lib\site-packages\pandas\core\generic.py", line 709, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Here's a snippet of the first 4 columns of my dataframe.
Zip keyword Prediction Numerator Prediction Denominator
0 01001 0 7650546.693200 40002.558782
1 01001 0 7650546.693200 40002.558782
2 01001 0 7650546.693200 40002.558782
3 01001 0 7650546.693200 40002.558782
4 01002 0 157.951741 0.718621
5 01002 0 157.951741 0.718621
6 01005 0 3600150.148240 20000.671431
7 01005 0 3600150.148240 20000.671431
8 01007 0 6932235.816260 30000.936191
9 01007 0 6932235.816260 30000.936191
10 01007 0 6932235.816260 30000.936191
Thanks, Ben