如何将pandas dataframe boolean列添加到一起以创建具有真值计数的列?在
例如,目的是创建“count”列:
a b c count
TRUE FALSE FALSE 1
TRUE TRUE FALSE 2
TRUE TRUE TRUE 3
在python中添加布尔值(例如True+True=2)之后,尝试:
^{pr2}$但没有起作用并发出警告:
UserWarning: evaluating in Python space because the '+' operator is not supported by numexpr for the bool dtype, use '|' instead
unsupported[op_str]))
这样做的目的是使筛选只有一个真实值的记录更容易。在
您可以使用
sum
函数,.sum(1)
将计算每行的真数:相关问题 更多 >
编程相关推荐