0
for i, row in lst.iterrows():
     value1 = a
     value2 = b
     result = 12345

     if df[(df['column1'] == value1) & (df['column2'] == value2)]:
          df['column_result'] == result 

print df

I want to look up in a dataframe a row where column1 equals value1 and column2 equals value2 and fill in result in that row.

I receive this error: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

2 Answers2

1

Try

df.loc[(df['column1'] == value1) & (df['column2'] == value2), 'column_result'] = result
Vaishali
  • 37,545
  • 5
  • 58
  • 86
0

The or and and python statements require truth-values. For pandas these are considered ambiguous so you should use "bitwise" | (or) or & (and) operations:

result = result[(result['var']>0.25) | (result['var']<-0.25)]

These are overloaded for these kind of datastructures to yield the element-wise or (or and).

More Info Here : Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

Robert I
  • 1,509
  • 2
  • 11
  • 18