find_or_check_datetime_variables#

feature_engine.variable_handling.find_or_check_datetime_variables(X, variables=None)[source]#

Returns the names of all the variables that are or can be parsed as datetime. Alternatively, it checks that the variables entered by the user can be parsed as datetime.

Note that this function will select variables cast as object if they can be cast as datetime as well.

More details in the User Guide.

Parameters
Xpandas dataframe of shape = [n_samples, n_features]

The dataset

variableslist, default=None

If None, the function returns the names of all variables in X that can be parsed as datetime. These include those cast as datetime, and also object and categorical if they can be transformed to datetime variables. Alternatively, it checks that the variables in the list are or can be parsed to datetime.

Returns
variables: List

The names of the datetime variables.

Examples

>>> import pandas as pd
>>> from feature_engine.variable_handling import find_or_check_datetime_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_date = find_or_check_datetime_variables(X)
>>> var_date
['var_date']
Return type

List[Union[str, int]]