pythonpands:添加布尔列以帮助过滤每个记录的一个真值

2024-03-28 22:04:58 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将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]))

这样做的目的是使筛选只有一个真实值的记录更容易。在


Tags: the目的falsetrue警告dataframepandascount