Drop columns whose name contains a specific string from pandas DataFrame

后端 未结 11 1953
臣服心动
臣服心动 2020-11-29 16:19

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 c

11条回答
  •  借酒劲吻你
    2020-11-29 17:22

    This can be done neatly in one line with:

    df = df.drop(df.filter(regex='Test').columns, axis=1)
    

提交回复
热议问题