find_categorical_and_numerical_variables#
- feature_engine.variable_handling.find_categorical_and_numerical_variables(X, variables=None, return_empty=False)[source]#
Find numerical and categorical variables in a dataframe or from a list.
The function returns two lists: the first with categorical variables and the second with numerical variables.
More details in the User Guide.
- Parameters
- Xpandas dataframe of shape = [n_samples, n_features]
The dataset.
- variableslist, default=None
If
None, the function finds all categorical and numerical variables in X. Alternatively, it finds categorical and numerical variables in X, selecting from the given list.- return_emptybool, default=False
Whether to return empty lists when no variables are found. If False, the function raises an error.
- Returns
- variables: tuple
Tuple containing a list with the categorical variables and a list with the numerical variables.
Examples
>>> import pandas as pd >>> from feature_engine.variable_handling import ( >>> find_categorical_and_numerical_variables >>>) >>> X = pd.DataFrame({ >>> "var_num": [1, 2, 3], >>> "var_cat": ["A", "B", "C"], >>> "var_date": pd.date_range("2020-02-24", periods=3, freq="T") >>> }) >>> var_cat, var_num = find_categorical_and_numerical_variables(X) >>> var_cat, var_num (['var_cat'], ['var_num'])