watex.utils.funcutils.map_specific_columns#
- watex.utils.funcutils.map_specific_columns(X, ufunc, columns_to_skip=None, pattern=None, inplace=False, **kws)[source]#
Apply function to a specific columns is the dataframe.
It is possible to skip some columns that we want operation to not be performed.
- Parameters:
X (dataframe,) – pandas dataframe with valid columns
ufunc (callable,) – Universal function that can be applying to the dataframe.
columns_to_skip (list or str ,) – List of columns to skip. If given as string and separed by the default pattern items, it should be converted to a list and make sure the columns name exist in the dataframe. Otherwise an error with raise.
pattern (str, default = '[#&*@!,;s]s*') –
The base pattern to split the text in column2skip into a columns For instance, the following string coulb be splitted to:
'depth_top, thickness, sp, gamma_gamma' -> ['depth_top', 'thickness', 'sp', 'gamma_gamma']
Refer to
str2columns()for further details.inplace (bool, default=True) – Modified dataframe in place and return None, otherwise return a new dataframe
kws (dict,) – Keywords argument passed to :func: pandas.DataFrame.apply function
- Returns:
X – Dataframe modified inplace with values computed using the given func`except the skipped columns, or ``None` if inplace is
True.- Return type:
Dataframe or None
Examples
>>> from watex.datasets import load_hlogs >>> from watex.utils.plotutils import map_specific_columns >>> X0, _= load_hlogs (as_frame =True ) >>> # let visualize the first3 values of `sp` and `resistivity` keys >>> X0['sp'][:3] , X0['resistivity'][:3] ... (0 -1.580000 1 -1.580000 2 -1.922632 Name: sp, dtype: float64, 0 15.919130 1 16.000000 2 24.422316 Name: resistivity, dtype: float64) >>> column2skip = ['hole_id','depth_top', 'depth_bottom', 'strata_name', 'rock_name', 'well_diameter', 'sp'] >>> map_specific_columns (X0, ufunc = np.log10, column2skip) >>> # now let visualize the same keys values >>> X0['sp'][:3] , X0['resistivity'][:3] ... (0 -1.580000 1 -1.580000 2 -1.922632 Name: sp, dtype: float64, 0 1.201919 1 1.204120 2 1.387787 Name: resistivity, dtype: float64) >>> # it is obvious the `resistiviy` values is log10 >>> # while `sp` stil remains the same