pandas.map

来源:互联网 发布:淘宝卖家信誉怎么算 编辑:程序博客网 时间:2024/06/06 03:06
Series.map(arg, na_action=None)[source]

Map values of Series using input correspondence (which can bea dict, Series, or function)

Parameters:

arg : function, dict, or Series

na_action : {None, ‘ignore’}

If ‘ignore’, propagate NA values, without passing them to themapping function

Returns:

y : Series

same index as caller

Examples

Map inputs to outputs

>>> xone   1two   2three 3
>>> y1  foo2  bar3  baz
>>> x.map(y)one   footwo   barthree baz

Use na_action to control whether NA values are affected by the mappingfunction.

>>> s = pd.Series([1, 2, 3, np.nan])
>>> s2 = s.map(lambda x: 'this is a string {}'.format(x),               na_action=None)0    this is a string 1.01    this is a string 2.02    this is a string 3.03    this is a string nandtype: object
>>> s3 = s.map(lambda x: 'this is a string {}'.format(x),               na_action='ignore')0    this is a string 1.01    this is a string 2.02    this is a string 3.03                     NaNdtype: object


http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html
0 0
原创粉丝点击