How to get line by line output using xlsWriterr

I just print line by line from the loop, and my output looks 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'] 

But in my excel output, I just get the first line something like this:

enter image description here

My expected result:

enter image description here

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.

+5
source share
1 answer

The problem is that you are rewriting the column with new values ​​at each iteration. Your code should look something like this:

 #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 must leave the DataList outside the outer loop and update the worksheet outside of this 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() 
+1
source

Source: https://habr.com/ru/post/1233496/


All Articles