diff --git a/doc/redirects.csv b/doc/redirects.csv index 5d351680ec03a..8c46cb520cc95 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -311,7 +311,6 @@ generated/pandas.DataFrame.align,../reference/api/pandas.DataFrame.align generated/pandas.DataFrame.all,../reference/api/pandas.DataFrame.all generated/pandas.DataFrame.any,../reference/api/pandas.DataFrame.any generated/pandas.DataFrame.apply,../reference/api/pandas.DataFrame.apply -generated/pandas.DataFrame.applymap,../reference/api/pandas.DataFrame.applymap generated/pandas.DataFrame.as_blocks,../reference/api/pandas.DataFrame.as_blocks generated/pandas.DataFrame.asfreq,../reference/api/pandas.DataFrame.asfreq generated/pandas.DataFrame.as_matrix,../reference/api/pandas.DataFrame.as_matrix @@ -747,8 +746,6 @@ generated/pandas.Interval.overlaps,../reference/api/pandas.Interval.overlaps generated/pandas.interval_range,../reference/api/pandas.interval_range generated/pandas.Interval.right,../reference/api/pandas.Interval.right generated/pandas.io.formats.style.Styler.apply,../reference/api/pandas.io.formats.style.Styler.apply -generated/pandas.io.formats.style.Styler.applymap,../reference/api/pandas.io.formats.style.Styler.map -generated/pandas.io.formats.style.Styler.applymap_index,../reference/api/pandas.io.formats.style.Styler.map_index generated/pandas.io.formats.style.Styler.background_gradient,../reference/api/pandas.io.formats.style.Styler.background_gradient generated/pandas.io.formats.style.Styler.bar,../reference/api/pandas.io.formats.style.Styler.bar generated/pandas.io.formats.style.Styler.clear,../reference/api/pandas.io.formats.style.Styler.clear @@ -1432,8 +1429,6 @@ reference/api/pandas.arrays.PandasArray,pandas.arrays.NumpyExtensionArray reference/api/pandas.core.groupby.DataFrameGroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill reference/api/pandas.core.groupby.GroupBy.backfill,pandas.core.groupby.DataFrameGroupBy.bfill reference/api/pandas.core.resample.Resampler.backfill,pandas.core.resample.Resampler.bfill -reference/api/pandas.io.formats.style.Styler.applymap,pandas.io.formats.style.Styler.map -reference/api/pandas.io.formats.style.Styler.applymap_index,pandas.io.formats.style.Styler.map_index # EWM -> ExponentialMovingWindow reference/api/pandas.core.window.ewm.EWM.corr,pandas.core.window.ewm.ExponentialMovingWindow.corr diff --git a/doc/source/reference/frame.rst b/doc/source/reference/frame.rst index 149498a4d2b85..d09ca416e32a6 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -117,7 +117,6 @@ Function application, GroupBy & window DataFrame.apply DataFrame.map - DataFrame.applymap DataFrame.pipe DataFrame.agg DataFrame.aggregate diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index c8e67710c85a9..7643828ca5a63 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -91,8 +91,8 @@ will be completed: df2.any df2.combine df2.append df2.D df2.apply df2.describe - df2.applymap df2.diff df2.B df2.duplicated + df2.diff As you can see, the columns ``A``, ``B``, ``C``, and ``D`` are automatically tab completed. ``E`` and ``F`` are there as well; the rest of the attributes have been diff --git a/doc/source/whatsnew/v0.20.0.rst b/doc/source/whatsnew/v0.20.0.rst index 09bf5428d0432..f63db945165e7 100644 --- a/doc/source/whatsnew/v0.20.0.rst +++ b/doc/source/whatsnew/v0.20.0.rst @@ -369,7 +369,6 @@ Experimental support has been added to export ``DataFrame.style`` formats to Exc For example, after running the following, ``styled.xlsx`` renders as below: .. ipython:: python - :okwarning: np.random.seed(24) df = pd.DataFrame({'A': np.linspace(1, 10, 10)}) @@ -379,7 +378,7 @@ For example, after running the following, ``styled.xlsx`` renders as below: df.iloc[0, 2] = np.nan df styled = (df.style - .applymap(lambda val: 'color:red;' if val < 0 else 'color:black;') + .map(lambda val: 'color:red;' if val < 0 else 'color:black;') .highlight_max()) styled.to_excel('styled.xlsx', engine='openpyxl') diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 8b8f5bf3d028c..aa378faac2a00 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -106,6 +106,7 @@ Removal of prior version deprecations/changes - :func:`read_excel`, :func:`read_json`, :func:`read_html`, and :func:`read_xml` no longer accept raw string or byte representation of the data. That type of data must be wrapped in a :py:class:`StringIO` or :py:class:`BytesIO` (:issue:`53767`) - All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`) - Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`) +- Removed :meth:`DataFrame.applymap`, :meth:`Styler.applymap` and :meth:`Styler.applymap_index` (:issue:`52364`) - Removed ``DataFrame.bool`` and ``Series.bool`` (:issue:`51756`) - Removed ``DataFrame.first`` and ``DataFrame.last`` (:issue:`53710`) - Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 591c02933c4bc..a62c3c8cd537a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -227,7 +227,6 @@ MergeHow, MergeValidate, MutableMappingT, - NaAction, NaPosition, NsmallestNlargestKeep, PythonFuncType, @@ -10150,60 +10149,6 @@ def infer(x): return self.apply(infer).__finalize__(self, "map") - def applymap( - self, func: PythonFuncType, na_action: NaAction | None = None, **kwargs - ) -> DataFrame: - """ - Apply a function to a Dataframe elementwise. - - .. deprecated:: 2.1.0 - - DataFrame.applymap has been deprecated. Use DataFrame.map instead. - - This method applies a function that accepts and returns a scalar - to every element of a DataFrame. - - Parameters - ---------- - func : callable - Python function, returns a single value from a single value. - na_action : {None, 'ignore'}, default None - If 'ignore', propagate NaN values, without passing them to func. - **kwargs - Additional keyword arguments to pass as keywords arguments to - `func`. - - Returns - ------- - DataFrame - Transformed DataFrame. - - See Also - -------- - DataFrame.apply : Apply a function along input axis of DataFrame. - DataFrame.map : Apply a function along input axis of DataFrame. - DataFrame.replace: Replace values given in `to_replace` with `value`. - - Examples - -------- - >>> df = pd.DataFrame([[1, 2.12], [3.356, 4.567]]) - >>> df - 0 1 - 0 1.000 2.120 - 1 3.356 4.567 - - >>> df.map(lambda x: len(str(x))) - 0 1 - 0 3 4 - 1 5 5 - """ - warnings.warn( - "DataFrame.applymap has been deprecated. Use DataFrame.map instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self.map(func, na_action=na_action, **kwargs) - # ---------------------------------------------------------------------- # Merging / joining methods diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index c51122fe9e140..6d124bec72137 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -549,11 +549,11 @@ class CSSWarning(UserWarning): Examples -------- >>> df = pd.DataFrame({"A": [1, 1, 1]}) - >>> df.style.applymap(lambda x: "background-color: blueGreenRed;").to_excel( + >>> df.style.map(lambda x: "background-color: blueGreenRed;").to_excel( ... "styled.xlsx" ... ) # doctest: +SKIP CSSWarning: Unhandled color format: 'blueGreenRed' - >>> df.style.applymap(lambda x: "border: 1px solid red red;").to_excel( + >>> df.style.map(lambda x: "border: 1px solid red red;").to_excel( ... "styled.xlsx" ... ) # doctest: +SKIP CSSWarning: Unhandled color format: 'blueGreenRed' diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 7be23b69dfa09..31e025ace4b03 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -12,7 +12,6 @@ Callable, overload, ) -import warnings import numpy as np @@ -23,7 +22,6 @@ Substitution, doc, ) -from pandas.util._exceptions import find_stack_level import pandas as pd from pandas import ( @@ -2011,42 +2009,6 @@ def map_index( ) return self - def applymap_index( - self, - func: Callable, - axis: AxisInt | str = 0, - level: Level | list[Level] | None = None, - **kwargs, - ) -> Styler: - """ - Apply a CSS-styling function to the index or column headers, elementwise. - - .. deprecated:: 2.1.0 - - Styler.applymap_index has been deprecated. Use Styler.map_index instead. - - Parameters - ---------- - func : function - ``func`` should take a scalar and return a string. - axis : {{0, 1, "index", "columns"}} - The headers over which to apply the function. - level : int, str, list, optional - If index is MultiIndex the level(s) over which to apply the function. - **kwargs : dict - Pass along to ``func``. - - Returns - ------- - Styler - """ - warnings.warn( - "Styler.applymap_index has been deprecated. Use Styler.map_index instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self.map_index(func, axis, level, **kwargs) - def _map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler: func = partial(func, **kwargs) # map doesn't take kwargs? if subset is None: @@ -2117,36 +2079,6 @@ def map(self, func: Callable, subset: Subset | None = None, **kwargs) -> Styler: ) return self - @Substitution(subset=subset_args) - def applymap( - self, func: Callable, subset: Subset | None = None, **kwargs - ) -> Styler: - """ - Apply a CSS-styling function elementwise. - - .. deprecated:: 2.1.0 - - Styler.applymap has been deprecated. Use Styler.map instead. - - Parameters - ---------- - func : function - ``func`` should take a scalar and return a string. - %(subset)s - **kwargs : dict - Pass along to ``func``. - - Returns - ------- - Styler - """ - warnings.warn( - "Styler.applymap has been deprecated. Use Styler.map instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return self.map(func, subset, **kwargs) - def set_table_attributes(self, attributes: str) -> Styler: """ Set the table attributes added to the ``