如果我有一个列名列表,如果这些列的值大于零,我想对行进行筛选,我能做些类似的事情吗?在
columns = ['colA','colB','colC','colD','colE','colF']
new_df = df.filter(any([df[c]>0 for c in columns]))
这将返回:
ValueError: Cannot convert column into bool: please use '&' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions
我想我可以将这些列和过滤器只在一列上求和(因为我没有负数)。但如果我有求和技巧就行不通了。不管怎样,如果我必须在不同于求和的条件下过滤这些列,我怎么能做我想做的事情呢? 有什么想法吗?在
您可以改为使用
or_
运算符:编辑:更多pythonista解决方案:
^{pr2}$编辑2:完整示例:
相关问题 更多 >
编程相关推荐