Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select column names not in list of names

Tags:

python

pandas

I have a list of column names from a dataframe and would like to generate a second list of column names that excludes everything in that first list.

I was thinking something like features=x[~x[exclude_features]].columns

(where exclude_features is a list of column names to exclude, but that throws an error. Thanks for the help!

like image 273
yogz123 Avatar asked Sep 19 '25 04:09

yogz123


1 Answers

Let us try

features=x.loc[:, ~x.columns.isin(exclude_features)].copy()

Or

features=x.loc[:, x.columns.difference(exclude_features)].copy()
like image 53
BENY Avatar answered Sep 23 '25 10:09

BENY