This is stumping me with pandas.. I have a data frame with 5.8M rows and a date index. I 5 columns A, B, C, D & E and would simply like to create a new column F_Score based on simple math below:
F_Score=0
if A > = B:
F_Score = 1.0
else:
F_Score= -1.0
if B > = C:
F_Score = F_Score + 1.0
else:
F_Score = F_Score - 1.0
if C > = D:
F_Score = F_Score + 1.0
else:
F_Score = F_Score-1.0
if D > = E:
F_Score = F_Score + 1.0
else:
F_Score = F_Score -1.0
I cannot seem to find a simple way to do this. Any suggestions?
I tried turning all of the columns into numpy arrays and then doing a for loop storing the result into a new array and then creating a column F for the dataframe. This seems very inefficient. Is there a better way?