Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have a pandas dataframe with the following column names:

Result1, Test1, Result2, Test2, Result3, Test3, etc...

I want to drop all the columns whose name contains the word "Test". The numbers of such columns is not static but depends on a previous function.

How can I do that?

1 Answer

0 votes
by (41.4k points)

Here is a better way to do this:

df = df[df.columns.drop(list(df.filter(regex='Test')))]

Browse Categories

...