Python map() 函數(shù)

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

RUNOOB,com鏈接

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

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

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