Ruby Write in CSV file by columns from arrays? -


i generate csv file severals arrays. code:

require 'csv' csv.open("csvfile.csv", "ab") |csv| csv << [array1] csv << [array2] csv << [array3] end 

i need output format:

array1,array2,array3 array1,array2,array3 array1,array2,array3 array1,array2,array3 array1,array2,array3 

thx help

according post, did mean array1, array2, array3 stores values of 3 columns of table, , row index identified index of values in these arrays? can first group columns together, transpose on 2-d array , write csv file row row.

require 'csv' table = [array1, array2, array3].transpose csv.open('csvfile.csv', 'ab') |csv|     table.each |row|         csv << row     end end 

you'll csv file this:

array1[0], array2[0], array3[0] array1[1], array2[1], array3[1] array1[2], array2[2], array3[2] ... 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -