find_categorical_and_numerical_variables#
- feature_engine.variable_handling.find_categorical_and_numerical_variables(X, variables=None)[source]#
Find numerical and categorical variables in a dataframe or from a list.
The function returns two lists; the first one with the names of the variables of type object or categorical and the second list with the names of the 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 will find all categorical and numerical variables in X. Alternatively, it will find categorical and numerical variables in X, selecting from the given list.
- Returns
- variables: tuple
Tupe 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'])