First install Torch7 (www.torch.ch) then simply install this package using luarocks:
luarocks install csvigo
The library provides 2 high-level functions: csvigo.load and csvigo.save. To get help on these functions, simply do:
> csvigo.save()
> csvigo.load()
Loading a CSV file in 'query' mode gives you a convenient query function that you can use to query subsets of your original CSV file. To get help on this query function, simply do:
> query = csvigo.load{path='somefile.csv', mode='query'}
> query('help')
-- print some help
> all = query('all')
> subset = query('union', {somevar=someval, someothervar={val1, val2}})
CSVigo supports efficient loading of very large CSV files into memory. The loaded data structure is a read-only table with efficiency hidden under the hood.
Loading:
m=csvigo.load({path="my_large.csv", mode="large"})Printing by default only prints first 10 and last 10 rows
print(m)Individual element access
print(m[32])Size of table:
print(#m)For loop over entries:
Type 1:
fori=1, #mdoprint(m[i]) -- get elementendType 2:
fork,vinipairs(m) doprint(k)
print(v)
endType 3:
fork,vinpairs(m) doprint(k)
print(v)
endRead-only table
-- read only table, will error here:m[13] ='a'