Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

adding array into multiple column in python

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

You can use * to unpack the list

wr.writerow(['Daily Journal (Park Hills, MO)',"Jan","2003",result,*pages])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading