I am trying to compare the values of a particular column with one of columns, and store the result to a new column based upon their comparison index, say: Low if value differ by more than 10%, and OK if otherwise.
df["Index"] = ""
def function(df):
for i in range(1, len(df.columns)-2):
if((df.columns.values[1]) == (df.columns.values[i+1])):
if((df.iloc[:,1]) < (0.9 * df.iloc[:,i+1])):
df["Index"] = "Low"
else:
df["Index"] = "OK"
function(df)
What is the relation of
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
to this? Would be great if someone can as well suggest ways to reduce the time complexity using same code structure.