我正在尝试设置fastercsv,以便它不是解析每一行,而是将每一列放入一个多数组中。
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任何帮助都是非常感谢的。
发布于 2009-11-03 03:22:34
感谢EmFi,在你的帮助下,我想出了一个解决方案。
这将获取远程url csv文件,并将其加载到基于列的多维数组中。
require 'rio'
require 'fastercsv'
url = 'http://remoteurl.com/file.csv'
people = FasterCSV.parse(rio(url).read)发布于 2009-11-02 14:58:27
你读过FasterCSV documentation?吗?
如果你这样做了,你就会知道做你想做的事情最简单的方法是:
people = FasterCSV.read('http://url.com/file.csv')发布于 2009-11-03 19:23:17
您可以在FasterCSV之上使用CsvMapper,它是救命稻草。
https://stackoverflow.com/questions/1659552
复制相似问题