watex.utils.to_numeric_dtypes#
- watex.utils.to_numeric_dtypes(arr, *, columns=None, return_feature_types=False, missing_values=nan, pop_cat_features=False, verbose=False)[source]#
Convert array to dataframe and coerce arguments to appropriate dtypes.
- Parameters:
arr (Ndarray or Dataframe, shape (M=samples, N=features)) – Array of dataframe to create
columns (list of str, optional) – Usefull to create a dataframe when array is given. Be aware to fit the number of array columns (shape[1])
return_feature_types (bool, default=False,) – return the list of numerical and categorial features
missing_values (float:) – Replace the missing or empty string if exist in the dataframe.
pop_cat_features (bool, default=False,) – remove removes the categorial features from the DataFrame.
verbose (bool, default=False,) – outputs a message by listing the categorial items dropped from the dataframe if exists.
- Returns:
df or (df, nf, cf) – also return nf and cf if return_feature_types is set to``True``.
- Return type:
Dataframe of values casted to numeric types
Examples
>>> from watex.datasets.dload import load_bagoue >>> from watex.utils.funcutils import to_numeric_dtypes >>> X, y = load_bagoue (as_frame =True ) >>> X0 =X[['shape', 'power', 'magnitude']] >>> X0.dtypes ... shape object power object magnitude object dtype: object >>> df = to_numeric_dtypes(X0) >>> df.dtypes ... shape object power float64 magnitude float64 dtype: object