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().
尝试
df.loc[(df['column1'] == value1) & (df['column2'] == value2), 'column_result'] = result
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.