1. 遍历

def square(x) :   # 计算平方数
    return x ** 2
a = [1,2,3,4,5]
for i in range(len(a)):
    a[i] = square(a[i])

2. 推导式

def square(x) :   # 计算平方数
    return x ** 2
a = [1,2,3,4,5]
a = [square(item) for item in a]

3. map函数

def square(x) :   # 计算平方数
    return x ** 2
a = [1,2,3,4,5]
a = list(map(square, a))

 

一维数组变二维数组,行变列:

a = pd.Series([1,2,3,4,5])
print(a)
b = a.values[:, None]  # 一维变二维 行变列
print(b)
c = b.T  # 转置
print(c)

 

posted on 2022-06-21 17:02  风生水起  阅读(681)  评论(0编辑  收藏  举报