Python map() 函數(shù)

python的 "map(function, iterable, ...)" 函數(shù)是一個(gè)內(nèi)置函數(shù),接收
function 參數(shù)和 iterable 參數(shù)。

上段示例代碼先:
\# 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)

輸出結(jié)果為:

image.png

可以發(fā)現(xiàn)兩種寫法的輸出結(jié)果略有不同,但關(guān)鍵信息是相同的。

還可以參考相關(guān)資料,如下:

官方文檔描述:

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() 會(huì)根據(jù)提供的函數(shù)對(duì)指定序列做映射。
第一個(gè)參數(shù) function 以參數(shù)序列中的每一個(gè)元素調(diào)用 function 函數(shù),返回包含每次 function 函數(shù)返回值的新列表。

RUNOOB,com鏈接

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • PYTHON-進(jìn)階-ITERTOOLS模塊小結(jié)轉(zhuǎn)自wklken:http://wklken.me/posts/20...
    C_Y_閱讀 1,166評(píng)論 0 2
  • # 第一優(yōu)先級(jí)規(guī)則聲明: # 除了夢(mèng)境,每一個(gè)意識(shí)主進(jìn)程都必須與一個(gè)身體參與的機(jī)械進(jìn)程相匹配,否則結(jié)束意識(shí)主進(jìn)程。...
    李洞BarryLi閱讀 4,196評(píng)論 0 1
  • 個(gè)人筆記,方便自己查閱使用 Py.LangSpec.Contents Refs Built-in Closure ...
    freenik閱讀 67,945評(píng)論 0 5
  • 今天說(shuō)說(shuō)這個(gè)有用和沒用的東西。 不管是以前還是現(xiàn)在,人們都喜歡有用的東西,不喜歡沒用的東西。 甚至罵人的時(shí)候都罵“...
    一葉茶閱讀 576評(píng)論 0 3
  • 1. 前幾天太陽(yáng)學(xué)長(zhǎng)實(shí)習(xí)歸來(lái),準(zhǔn)備畢業(yè)論文,找我搜集資料的時(shí)候突然來(lái)了那么一句:“其實(shí)這四年過(guò)得挺平淡的,每天上上...
    蘇小燦閱讀 704評(píng)論 1 4

友情鏈接更多精彩內(nèi)容