What is a quick way to remove columns in pandas data from a list of column names

I am trying to figure out how to quickly remove columns in df using a list of column names. this is a fancy feature reduction technique. This is what I use now, and it happens forever. Any suggestions are welcome.

important2=(important[:-(len(important)-500)]) for i in important: if i in important2: pass else: df_reduced.drop(i, axis=1, inplace=True) df_reduced.head() 
+6
source share
1 answer

use a list containing the columns to be deleted

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

Source: https://habr.com/ru/post/1012325/


All Articles