Python——保存矩阵为Excel

def save(data, path):
    f = xlwt.Workbook()  # 创建工作簿
    sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True)  # 创建sheet
    [h, l] = data.shape  # h为行数,l为列数
    for i in range(h):
        for j in range(l):
            sheet1.write(i, j, data[i, j])
    f.save(path)
代码简单,但是常用

猜你喜欢

转载自blog.csdn.net/ling_cmd/article/details/81063794