Created
June 24, 2023 17:54
-
-
Save simonespa/e109692ace27b1807ff3c8cde7ff08f3 to your computer and use it in GitHub Desktop.
Split categorical from numerical features with Pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # split numerical variables from categorical | |
| numerical = train.select_dtypes('number') | |
| categorical = train.select_dtypes(exclude='number') | |
| # split high cardinality categorical variables from the low cardinality ones | |
| hc_categorical = categorical[[col for col in categorical.columns if categorical[col].nunique() > 20]] | |
| lc_categorical = categorical[[col for col in categorical.columns if categorical[col].nunique() <= 20]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment