numpy.array插入一行或一列spa
import numpy as np a = np.array([[1,2,3],[4,5,6],[7,8,9]]) b = np.array([[0,0,0]]) c = np.insert(a, 0, values=b, axis=0) d = np.insert(a, 0, values=b, axis=1) print(c) print(d)
結果:excel
>>c [[0 0 0] [1 2 3] [4 5 6] [7 8 9]] >>d [[0 1 2 3] [0 4 5 6] [0 7 8 9]]
場景:df的字段名和數據添加到excel表code