How did you build the non-numerical columns?

Here is what I did but feels like there’s simpler:

[numerical_columns.remove(x) for x in numerical_features]
categorical_columns_total = categorical_columns + numerical_columns

I used set subtraction.

categorical_features = list(set(data.columns) - set(numerical_features))

2 Likes

There did was a Pythonic way to do, I knew it… Thank you very much for the hint

Python Set | difference() - GeeksforGeeks.

Python Set | difference() - GeeksforGeeks.

Thanks for the link

Since you are manipulating Pandas indices, you can directly use their interface instead to convert into Python set:

categorical_features = data.columns.difference(numerical_features)
6 Likes

This is the Pandastic solution

3 Likes

we can also use:
categorical_features = data.drop(columns=numerical_features).columns

2 Likes