我是靠谱客的博主 内向冷风,这篇文章主要介绍pandas.map,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
>>> x one 1 two 2 three 3
复制代码
1
2
3
4
5
6
7
>>> y 1 foo 2 bar 3 baz
复制代码
1
2
3
4
5
6
>>> 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])
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
>>> 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
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
>>> 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


http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html

最后

以上就是内向冷风最近收集整理的关于pandas.map的全部内容,更多相关pandas内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部