adding array into multiple column in python

Question:

I have an array that I want to append as multiple columns
what I am getting

what I want

pages = [1,2,3,4,5,6]
with open(nlnewsdata, 'a',newline='') as nlnews:
wr = csv.writer(nlnews, quoting=csv.QUOTE_ALL)
wr.writerow(['Daily Journal (Park Hills, MO)',"Jan","2003",result,pages])

now the output Im expecting is like this

Daily Journal (Park Hills, MO), Jan , 2003, 6, 1,2,3,4,5,6

what Im getting is

Daily Journal (Park Hills, MO), Jan,2003,6,1 2 3 4 5 6

I want to split the array into different columns not all the pages in a single column
I have tried np.savetext and pages.tofile but the thing is I am adding some data row by row and on the same run I want this array to split across multiple columns too.

Asked By: snoozy

||

Answers:

You can use * to unpack the list

wr.writerow(['Daily Journal (Park Hills, MO)',"Jan","2003",result,*pages])
Answered By: Ynjxsjmh
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.