Pandas 如何在不使用if语句的情况下,通过检查多个包含True和False的列来返回列

Pandas 如何在不使用if语句的情况下,通过检查多个包含True和False的列来返回列,pandas,list,dataframe,if-statement,list-comprehension,Pandas,List,Dataframe,If Statement,List Comprehension,如何在不使用if语句的情况下获得所需的输出?并逐行检查 import pandas as pd test = pd.DataFrame() test['column1'] = [True, True, False] test['column2']= [False,True,False] index column1 column2 0 True False 1 True True 2 False Fal

如何在不使用if语句的情况下获得所需的输出?并逐行检查

import pandas as pd 

test = pd.DataFrame()
test['column1'] = [True, True, False]
test['column2']= [False,True,False]

index   column1     column2

0         True      False
1         True      True
2         False     False

desired output:

index   column1     column2   column3

0         True      False     False
1         True      True      True
2         False     False     False


非常感谢你的帮助

提前感谢。

如果所有值均为
True,则用于测试:

test['column3'] = test.all(axis=1)
如果需要筛选列,请添加子集
['column1','column1']

test['column3'] = test[['column1','column1']].all(axis=1)
如果需要测试,则可以在此处仅测试两列,对按位
使用
&

test['column3'] = test['column1'] & test['column1']
如果所有值均
True
s,则用于测试:

test['column3'] = test.all(axis=1)
如果需要筛选列,请添加子集
['column1','column1']

test['column3'] = test[['column1','column1']].all(axis=1)
如果需要测试,则可以在此处仅测试两列,对按位
使用
&

test['column3'] = test['column1'] & test['column1']