python - 为什么我会收到 ValueError:Series 的真值不明确?
问题描述
我知道之前有人问过类似的问题,但我很难理解为什么会出现这个错误。
我正在使用下面的代码创建一个新列,如果“价格”在上限“price_h2”和下限“price_h1”之内,则该行被标记为异常值
df_test['price_outlier'] = np.where( df_test['price_h1'] <= df_test['price'] <= df_test['price_h2'],'normal','outlier')
非常感谢帮助!
解决方案
因为 numpy 数组不支持语法: a < x < b
您需要使用括号来分隔两个子句(a < x) & (x < b):
df_test['price_outlier'] = np.where((df_test['price_h1'] <= df_test['price']) &\
(df_test['price'] <= df_test['price_h2']),
'normal', 'outlier')
推荐阅读
- javascript - React.js 使用地图时创建新行
- c++ - 当该数组的索引中没有元素时,指针指向的是什么?
- docker - 是否可以将 awslog 与 gitlab-ci 自动缩放运行器一起使用?
- typescript - 在 Typescript 中返回 Promise 的 Promise 不会编译
- python - 无法使用 Selenium 访问站点 https://www.sahbinden.com
- c# - 从远程进程获取标准输入
- html - 元素意外占据了其容器的整个高度
- reactjs - 即使未达到 30 分钟阈值,Firestore 也会在每个侦听器打开时读取
- angular - Angular Validator,检查电子邮件是否对数据库集或登录用户的当前电子邮件是唯一的
- java - java中测验应用解决方案活动中的错误?