如何按条件删除列? [英] How to drop columns by criteria?
本文介绍了如何按条件删除列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设df
是熊猫DataFrame
对象.
如何删除
df
中仅包含None
,空字符串或仅空白字符串的所有列?
How do I drop all the columns of
df
that contain onlyNone
, empty strings, or white-space-only strings?
删除的标准可以表示为当这些列输入以下测试函数时所有值均产生True
的列:
The criterion for dropping could be expressed as those columns where all the values yield True
when fed to the following test function:
lambda x: (x is None) or not re.match('\S', str(x))
推荐答案
您可以使用 查看全文