Python map() 函数

python的 "map(function, iterable, ...)" 函数是一个内置函数,接收
function 参数和 iterable 参数。

上段示例代码先:
\# coding:utf8 import pandas as pd dict = { 'score_season01': pd.Series([5, 4, 5], index=['will', 'alice', 'mac']), 'score_season02': pd.Series([3, 4, 3], index=['will', 'alice', 'mac']) } res = pd.DataFrame(dict) print res print '************' \# 第一种写法: print map(lambda x: x > 4, res['score_season01']) print '************' \# 第二种写法: print res['score_season01'].map(lambda x: x > 4)

输出结果为:

image.png

可以发现两种写法的输出结果略有不同,但关键信息是相同的。

还可以参考相关资料,如下:

官方文档描述:

map (function, iterable, ...)
Return an iterator that applies function to every item of iterable, yielding the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is exhausted. For cases where the function inputs are already arranged into argument tuples, see itertools.starmap()
.

官方文档链接(python2.x版本)

RUNOOB.com 描述:

map() 会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。

RUNOOB,com链接

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容