简体   繁体   中英

How to write multiple arrays into a csv file

I am trying to write a code to write multiple arrays into one single data frame in panda where I append the data frame row by row. For example I have a row of [1,2,3,4,5] and next row of [6,7,8,9,10]. I want to print it as: 1,2,3,4,5 6,7,8,9,10 in a csv file. I want to write multiple rows like this in single csv file but all codes can be found only for appending a data frame column by column. Can I write this array row by row too? Please help.

I tried using pandas library but couldn't fine relevant command.

the next code snippet might help you:

import csv
with open('file.csv', 'w') as f:
    writer = csv.writer(f)
    writer.writerows([[1,2,3], [4,5,6]]) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM