如何编写Python阵列(数据= [])脱颖而出? [英] how to write python array (data = []) to excel?

查看:131
本文介绍了如何编写Python阵列(数据= [])脱颖而出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Python程序来处理.HDF文件,我想这个数据输出到Excel US preadsheet。我把数据放到一个数组,如下所示:

I am writing a python program to process .hdf files, I would like to output this data to an excel spreadsheet. I put the data into an array as shown below:

code:

data = []

for rec in hdfFile[:]:
    data.append(rec)

在这里,我已经创建了9列和171行的二维数组。

from here I have created a 2D array with 9 columns and 171 rows.

我要寻找一种方法,通过这个数组迭代和写入,以表中的每个条目。我想知道如果要是我应该创建一个列表,而不是,或如何做到这一点与
数组我创建。

I am looking for a way to iterate through this array and write each entry in order to a sheet. I am wondering if If I should create a list instead, or how to do this with the array I have created.

任何帮助将大大AP preciated。

Any help would be greatly appreciated.

推荐答案

就像@senderle说,使用csv.writer

Just like @senderle said, use csv.writer

a = [[1,2,3],[4,5,6],[7,8,9]]
ar = array(a)

import csv

fl = open('filename.csv', 'w')

writer = csv.writer(fl)
writer.writerow(['label1', 'label2', 'label3']) #if needed
for values in ar:
    writer.writerow(values)

fl.close()    

这篇关于如何编写Python阵列(数据= [])脱颖而出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆