当前位置:主页 > 软件编程 > Python代码 >

Python 保存矩阵为Excel的实现方法

时间:2021-03-10 09:24:43 | 栏目:Python代码 | 点击:

如下所示:

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)

代码简单,但是常用!

您可能感兴趣的文章:

相关文章