根据字符串条件删除列 [英] drop column based on a string condition
本文介绍了根据字符串条件删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据名称中的某个字符串删除数据框列?
How can I delete a dataframe column based on a certain string in its name?
示例:
house1 house2 chair1 chair2
index
1 foo lee sam han
2 fowler smith had sid
3 cle meg mag mog
我想删除字符串中包含 chair的列。
如何有效地做到这一点?
谢谢。
I want to drop the columns that contain 'chair' in the string. How can this be done in an efficient way? Thanks.
推荐答案
df.drop([col for col in df.columns if 'chair' in col],axis=1,inplace=True)
这篇关于根据字符串条件删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文