[英]FasterCSV: columns into an array — rails
我試圖獲得更快的csv設置,以便將其而不是解析每一行,而是將每一列放入一個多數組中。
CSV import file:
id, first name, last name, age
1, joe, smith, 11
2, jane, doe, 14
Save to array named people:
people[0][0] would equal id
people[2][1] would equal jane
這是我目前擁有的:
url = 'http://url.com/file.csv'
open(url) do |f|
f.each_line do |line|
FasterCSV.parse(line) do |row|
row
end
end
end
任何幫助表示贊賞。
感謝EmFi,在您的幫助下,我提出了解決方案。
這將獲取一個遠程url csv文件,並根據列將其加載到多維數組中。
require 'rio'
require 'fastercsv'
url = 'http://remoteurl.com/file.csv'
people = FasterCSV.parse(rio(url).read)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.