如何根据名称中的特定字符串删除数据框列?
例子:
house1 house2 chair1 chair2
index
1 foo lee sam han
2 fowler smith had sid
3 cle meg mag mog
我想删除字符串中包含“椅子”的列。 如何以有效的方式做到这一点? 谢谢。
最佳答案
df.drop([col for col in df.columns if 'chair' in col],axis=1,inplace=True)
关于python - 根据字符串条件删除列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38383886/