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)
輸出結果為:
可以發現兩種寫法的輸出結果略有不同,但關鍵信息是相同的。
還可以參考相關資料,如下:
官方文檔描述:
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() 會根據提供的函數對指定序列做映射。
第一個參數 function 以參數序列中的每一個元素調用 function 函數,返回包含每次 function 函數返回值的新列表。