如何按条件删除列? [英] How to drop columns by criteria?

查看:65
本文介绍了如何按条件删除列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设df是熊猫DataFrame对象.

如何删除df中仅包含None,空字符串或仅空白字符串的所有列?

How do I drop all the columns of df that contain only None, 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))

推荐答案

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆