我正在尝试使用以下代码对数据帧outlier_locations
应用布尔索引:
outlier_locations = month[(month.pickup_longitude != 0 and month.pickup_latitude != 0) & ((month.pickup_longitude <= -74.15) or (month.pickup_latitude <= 40.5774)or \
(month.pickup_longitude >= -73.7004) or (month.pickup_latitude>= 40.9176))]
但是,我得到了错误(下面是完整的回溯):
The truth value of a Series is ambiguous
为什么会发生这种情况?我能做些什么来修复它?你知道吗
对于Pandas系列的布尔索引,需要分别对“and”/“or”条件使用逐位
&
/|
运算符。为了便于阅读,您还可以将遮罩拆分为以下组件:将
and
和or
分别更改为&
和|
。你知道吗相关问题 更多 >
编程相关推荐