4

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!

1 Answer 1

5

Let us try

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

Or

features=x.loc[:, x.columns.difference(exclude_features)].copy()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.