Python Pandas结合了多个布尔系列
我有一个带有多个列的数据框,例如下面的
性别 | 婚姻 | 教育 |
---|---|---|
男性 | 单一 | 三级 |
我有一系列包含布尔式系列的要求,我需要使用&符号。
bool_gender = df["gender"] == "male"
bool_marital = df["marital"] == "married"
bool_education = df["education"] == "secondary"
[bool_gender, bool_marital, bool_education]
如何使用Python 3中的功能编程来组合列表中的所有项目,以获得以下表达式的单个布尔值:
desired output = bool_gender & bool_marital & bool_education
Possible use:
reduce("&", map(function, iter))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
操作员
模块和功能:you could do something like this with the
operator
module andfunctools.reduce
function:您可以使用
降低a>
numpy> numpy.bit.bit.and.bit_and
:You can use the
reduce
version ofnumpy.bitwise_and
: