jeudi 7 juillet 2016

writing arrays to csv


I am looping through 2d array (data) then populate fields using different segments of the arrays that I am looping over. Below is the sample code: with open('output.csv' , 'wb') as outcsv: headers = ['Field1', 'Field2', 'LongField'] writer = csv.DictWriter(outcsv, headers) writer.writeheader() for i in range(numArrays): row = [{'Field1': data[i][:3], 'Field2': data[i][3:5], 'LongField': data[i][5:]}] writer.writerows(row) I am getting the desired output for all fields except the 'LongField' where the number of values are large (hundreds, could be even few thousands) and varying. Here is what my output looks like: Field1 Field2 LongField 3,4,5 1,2 array([0,0,0,...,0,0,0]) 5,3,6 0,9 array([0,0,0,...,0,0,0]) Is this happening because im exceeding some kind of maximum allow values I can write to a cell? Is there a way for me to write all actual values into the cell? Any help will be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire