[英]How to look up and fill in data in dataframe python?
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. 我想在数据帧中查找column1等于value1且column2等于value2的行, 并将结果填充在该行中。
I receive this error: ValueError: The truth value of a DataFrame is ambiguous. 我收到此错误:ValueError:DataFrame的真实值不明确。 Use a.empty, a.bool(), a.item(), a.any() or a.all().
使用a.empty,a.bool(),a.item(),a.any()或a.all()。
尝试
df.loc[(df['column1'] == value1) & (df['column2'] == value2), 'column_result'] = result
The or
and and
python statements require truth-values. or
和and
python语句需要真值。 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
). 对于此类数据结构,它们会重载以产生按元素
or
(或and
)。
More Info Here : Truth value of a Series is ambiguous. 此处的更多信息: 系列的真值不明确。 Use a.empty, a.bool(), a.item(), a.any() or a.all()
使用a.empty,a.bool(),a.item(),a.any()或a.all()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.