Reputation: 942
I am simply printing line by line list from the loop and my output is something like this:
[' 4.0\n', ' 17.2\n', ' 7.0\n']
[' 0.0\n']
[' 4.0\n', ' 16.7\n', ' 4.0\n']
[' 4.0\n', ' 16.7\n', ' 4.0\n']
[' 4.0\n', ' 16.7\n', ' 4.0\n']
[' 4.0\n', ' 16.7\n', ' 4.0\n']
[' 4.0\n', ' 16.4\n', ' 4.0\n']
My current Code is here:
count = 0
DataList = []
for line, file in enumerate(PM2Line):
if POA in file:
DataList.append(file[32:50])
print DataList #--> this will print the list of output
worksheet.write_column('A1', DataList) #--> My problem is just getting first line.
workbook.close()
Any suggestion or comments.
Upvotes: 5
Views: 121
Reputation: 90979
The issue is that you are overwriting the column with new values in each iteration. Your code should be looking something like -
#some loop
count = 0
DataList = []
for line, file in enumerate(PM2Line):
if POA in file:
DataList.append(file[32:50])
print DataList #--> this will print the list of output
worksheet.write_column('A1', DataList) #--> My problem is just getting first line.
workbook.close()
You should keep the DataList
outside the outer loop and only update the worksheet outside that loop. Example -
#open worksheet here instead of inside the loop.
DataList = []
#some loop
count = 0
for line, file in enumerate(PM2Line):
if POA in file:
DataList.append(file[32:50])
print DataList
worksheet.write_column('A1', DataList)
workbook.close()
Upvotes: 1