Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10365,7 +10365,29 @@ def map(
0 1
0 3 4
1 5 5

<<<<<<< HEAD

>>> df.map(round, digits=2)
0 1
0 1.00 2.12
1 3.36 4.57
=======

>>> def foo(x):
if x > 2.5:
x = 2

elif x <= 2.5:
x = 1

return x

>>> df.map(foo)
0 1
0 1 1
1 2 2
>>>>>>> parent of 6f40da17ba (Updated Documentation for the map method)

Like Series.map, NA values can be ignored:

>>> df_copy = df.copy()
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10683,11 +10683,11 @@ def _where(
if not isinstance(cond, ABCDataFrame):
# This is a single-dimensional object.
if not is_bool_dtype(cond):
raise ValueError(msg.format(dtype=cond.dtype))
raise TypeError(msg.format(dtype=cond.dtype))
else:
for _dt in cond.dtypes:
if not is_bool_dtype(_dt):
raise ValueError(msg.format(dtype=_dt))
raise TypeError(msg.format(dtype=_dt))
if cond._mgr.any_extension_types:
# GH51574: avoid object ndarray conversion later on
cond = cond._constructor(
Expand Down