美文网首页
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高阶函数学习笔记

    python中的高阶函数是指能够接收函数作为参数的函数 python中map()函数map()是 Python 内...

  • Lesson 025 —— python 常用函数与深浅拷贝

    Lesson 025 —— python 常用函数与深浅拷贝 常用函数 map()map()是 Python 内置...

  • Python学习记录

    基本语法 Python lambda介绍 常用函数 python map( )函数用法map将传入的函数f依次作用...

  • python——list(map())函数的用法

    版本:python3.7 map()函数## map()是 Python 内置的高阶函数,它接收一个函数 f 和一...

  • Python的高级函数

    Python的高级函数 1. map函数 map(func, *itertables) 对itertables中...

  • map/reduce

    Python内建了map()和reduce()函数。 1、map()函数map()函数接收两个参数,一个是函数,一...

  • python 中的map(转载)

    1 map()函数的简介以及语法: map是python内置函数,会根据提供的函数对指定的序列做映射。 map()...

  • Python map函数

    python3中返回迭代器: 函数map lambda map

  • Python3 小技巧

    集合操作 字典操作 两个字典 相交、合并、相差 Python 映射 Python 内置函数 map();map()...

  • Python 18:map/reduce

    python内置可map()和reduce()函数。我们先看map。map()函数接收两个参数,一个是函数,一个是...

网友评论

      本文标题:Python map() 函数

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