如何在 pandas 中删除以相同文本结尾的多列? [英] How to remove multiple columns that end with same text in Pandas?
本文介绍了如何在 pandas 中删除以相同文本结尾的多列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除 数据集中的一组列.所有要删除的变量都以文本前缀"结尾.
I'm trying to remove a group of columns from a dataset. All of the variables to remove end with the text "prefix".
我使用以下方法设法将它们收集"到一个组中:
I did manage to "collect' them into a group using the following:
,然后尝试了一系列方法来删除该组,从而导致各种错误.任何人都可以提出删除这些列的方法吗?
and then tried a series of ways to drop that group that resulted in a variety of errors. Can anyone please, propose a way to remove these columns?
推荐答案
df2 = df.drop([col for col in df.columns if 'prefix' in col],axis=1)
这篇关于如何在 pandas 中删除以相同文本结尾的多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文