小编pri*_*ipe的帖子

根据条件创建布尔列

我有一个包含 11 列的数据框,我想根据其中两列中的值创建一个新的 0,1 列。

我已经尝试使用 np.where 创建其他列,但它不适用于这一列。

train["location"] = np.where(3750901.5068 <= train["x"] <= 3770901.5068 
and -19268905.6133 <= train['y'] <= -19208905.6133, 1, 0)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:ValueError:系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。

python numpy python-3.x pandas

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

numpy ×1

pandas ×1

python ×1

python-3.x ×1