【发布时间】:2022-07-08 20:25:39
【问题描述】:
我有一个看起来有点像这样的数据框:
cancelled | offer
----------|------
N | 123
N | 456
y | 789
我正在尝试使用 if 语句来标记数据框中是否有任何已取消的报价(即标记为“Y”或“y”的报价)。这是我到目前为止的代码:
if df["cancelled"].any().isin(["Y","y"]):
print("WARNING - Cancelled offers included!")
else:
print("OK - No cancelled offers are included.")
但是,当我运行它时,我收到以下错误:
AttributeError: 'numpy.bool_' object has no attribute 'isin'
显然 isin 函数与我的其余代码不兼容,但在这种情况下,获得所需结果的正确方法是什么?
【问题讨论】: