csv:from-file
csv:from-file csv-file csv:from-file csv-file delimiter
Parses an entire CSV file to a list of lists of values. For example, if we have a file example.csv
that contains:
1,2,3
4,5,6
7,8,9
10,11,12
Then, we get:
observer> show csv:from-file "example.csv"
observer: [[1 2 3] [4 5 6] [7 8 9] [10 11 12]]
The parser doesn’t care if the rows have different numbers of items on them. The number of items in the rows list will always be <number of delimiters> + 1
, though blank lines are skipped. This makes handling files with headers quite easy. For instance, if we have header.csv
that contains:
My Data
2/1/2015
Parameters:
start,stop,resolution,population,birth?
0,4,1,100,true
Data:
time,x,y
0,0,0
1,1,1
2,4,8
3,9,27
This gives:
observer> foreach csv:from-file "header.csv" show
observer: ["My Data"]
observer: ["2/1/2015"]
observer: ["Parameters:"]
observer: ["start" "stop" "resolution" "population" "birth?"]
observer: [0 4 1 100 true]
observer: ["Data:"]
observer: ["time" "x" "y"]
observer: [0 0 0]
observer: [1 1 1]
observer: [2 4 8]
observer: [3 9 27]
Take me to the full CSV Extension Dictionary