美文网首页
Python map() 函数

Python map() 函数

作者: TEJ | 来源:发表于2017-05-26 03:02 被阅读0次

    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链接

    相关文章

      网友评论

          本文标题:Python map() 函数

          本文链接:https://www.haomeiwen.com/subject/mkdtfxtx.html