1. 程式人生 > >Python——儲存矩陣為Excel

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)
程式碼簡單,但是常用