小编Luc*_*rra的帖子

根据条件创建布尔列

我有一个包含 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万
查看次数

如何使用 Python 将未知整数分成给定数量的偶数部分

我需要帮助才能将一个未知整数分成给定数量的偶数部分——或者至少尽可能均匀。各部分之和应为原始值,但各部分应为整数,且应尽可能接近。

Parameters
num: Integer - The number that should be split into equal parts

parts: Integer - The number of parts that the number should be split 
into

Return Value
List (of Integers) - A list of parts, with each index representing the part and the number contained within it representing the size of the part. The parts will be ordered from smallest to largest.
Run Code Online (Sandbox Code Playgroud)

这就是我所拥有的

Parameters
num: Integer - The number that should be split into equal parts

parts: …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

2
推荐指数
1
解决办法
1583
查看次数

标签 统计

python ×2

numpy ×1

pandas ×1

python-2.7 ×1

python-3.x ×1