-
Series.map(arg, na_action=None)
[source] -
Map values of Series using input correspondence (which can be a dict, Series, or function)
Parameters: arg : function, dict, or Series
na_action : {None, ?ignore?}
If ?ignore?, propagate NA values, without passing them to the mapping function
Returns: y : Series
same index as caller
Examples
Map inputs to outputs
1234>>> x
one
1
two
2
three
3
1234>>> y
1
foo
2
bar
3
baz
1234>>> x.
map
(y)
one foo
two bar
three baz
Use na_action to control whether NA values are affected by the mapping function.
1>>> s
=
pd.Series([
1
,
2
,
3
, np.nan])
1234567>>> s2
=
s.
map
(
lambda
x:
'this is a string {}'
.
format
(x),
na_action
=
None
)
0
this
is
a string
1.0
1
this
is
a string
2.0
2
this
is
a string
3.0
3
this
is
a string nan
dtype:
object
1234567>>> s3
=
s.
map
(
lambda
x:
'this is a string {}'
.
format
(x),
na_action
=
'ignore'
)
0
this
is
a string
1.0
1
this
is
a string
2.0
2
this
is
a string
3.0
3
NaN
dtype:
object
Series.map()

2025-01-10 15:47:30
Please login to continue.