map() 會根據提供的函數對指定序列做映射。
第一個參數 function 以參數序列中的每一個元素調用 function 函數,返回包含每次 function 函數返回值的新列表。
map(function, iterable, ...)
其中
- function -- 函數,有兩個參數
- iterable -- 一個或多個序列
-
>>> def square(x) : # 計算平方數... return x ** 2...
-
-
[ 1, 4, 9, 16, 25]
-
-
[ 1, 4, 9, 16, 25]
-
# 提供了兩個列表,對相同位置的列表數據進行相加
-
-
[ 3, 7, 11, 15, 19]
join() 方法用於將序列中的元素以指定的字符連接生成一個新的字符串。
str.join(sequence)
-
str = "-";
-
seq = ( "a", "b", "c"); # 字符串序列
-
print str.join( seq );
split()通過指定分隔符對字符串進行切片,如果參數num 有指定值,則僅分隔 num 個子字符串
str.split(str="", num=string.count(str))
- str -- 分隔符,默認為所有的空字符,包括空格、換行(\n)、制表符(\t)等。
- num -- 分割次數。
-
str = "this is string example....wow!!!"
-
print (str.split( ))
-
print (str.split('i',1))
-
print (str.split('w'))
-
-
[ 'this', 'is', 'string', 'example....wow!!!']
-
[ 'th', 's is string example....wow!!!']
-
[ 'this is string example....', 'o', '!!!']
data_4temp1['amount2'] = data_4temp1['amount'].map(lambda x: int(''.join(x[1:].split(','))))
原文地址:https://blog.csdn.net/abcdrachel/article/details/80520484