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é)果為:

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