【发布时间】:2022-06-22 20:28:24
【问题描述】:
我有一个包含多个列的数据框,如下所示
| gender | marital | education |
|---|---|---|
| male | single | tertiary |
我有一个包含布尔系列的需求列表,我需要使用 & 符号将它们全部组合起来。
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))
【问题讨论】:
标签: python pandas list functional-programming