在python3中直接使用map函数不会返回想要的结果:
print(map(lambda x: x * x, [1, 2, 3, 4]))
def f(x):
return x*x
print(list(map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])))
输出结果: [1, 4, 9, 10, 25, 36, 49, 64, 81] 配合匿名函数使用:
data = list(range(10))
print(list(map(lambda x: x * x, data)))
输出结果: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
在Pandas中的map函数还可以这样: