简体   繁体   中英

logical operation over all pandas dataframe columns

given the following dataframe,

      col1       col2        col3
0      True      True        False
1      True      True         True
2     False      True         True
3     False      True         True
4     False      True         True
5     False      True         True
6      True      True         True

I would like a new dataframe resulting in the calculation without considering the number of columns to AND:

df.col1 & df.col2 & df.col3 & etc...

In other terms, how to dynamically AND pandas dataframe columns?

Please assume all values are already boolean.

让我们尝试all =& 和any =|

df.all(axis=1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM