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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容