Python 错误提示TypeError: ufunc 'bitwise_or' not supported for the inp

分享
程序员 2024-9-17 16:49:08 70 0 来自 中国
Python错误提示:TypeError: ufunc 'bitwise_or' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
错误代码:
df['new_col'] = df.apply(lambda x: 0 if df['a'] == 0 | df['b'] == 0)搜索之后,题目在于两个if条件都必要用括号括起来,修改如下:
df['new_col'] = df.apply(lambda x: 0 if (df['a'] == 0) | (df['b'] == 0))继续报错:ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
继续修改,搜索到这个复兴# Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

上联有各种表明,末了根据情况需求选择了一种方案,修改如下:
df['new_col'] = df.apply(lambda x: 0 if (df['a'] == 0).any() | (df['b'] == 0).any())
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-19 04:31, Processed in 0.125437 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表