lrn2code lrn2code - 10 months ago 56
Python Question

what is the fast way to drop columns in pandas dataframe from a list of column names

I'm trying to figure out the fastest way to drop columns in df using a list of column names. this is a fancy feature reduction technique.
This is what I am using now, and it is taking forever. Any suggestions are highly appreciated.

for i in important:
if i in important2:
df_reduced.drop(i, axis=1, inplace=True)

Answer Source

use list containing the columns to be dropped

good_bye_list = ['column_1', 'column_2', 'column_3']
df_reduced.drop(good_bye_list, axis=1, inplace=True)