I work with large data sets with 22 columns and up to a million rows. Each row contains one observation with several variables. All variables are numbers.
Simplyfied example:
1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
4, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
(...)
First of all I need to import one row at a time, in the format {1,1,2,3,4,5,6,7,8,9,10}.
I have trouble getting Mathematica to ignore the blank spaces between the numbers unless I use the Import function. That is not a reasonable solution with very large data sets.
Can I use Mathematica's stream environment to solve this? If so, how?
Second, I eventually need to be able to import specific rows. For example all the rows where the second value is 2: {{1,1,2,3,4,5,6,7,8,9,10},{3,1,2,3,4,5,6,7,8,9,10}}.
Can that be done without having to import the entire dataset first?
ReadList["yourlist.txt", Number, RecordSeparators -> {","}]
? $\endgroup$Streaming`LazyList
; Reading specific entries from a CSV file; How toImport
random elements of huge data files. $\endgroup$ReadList
a line at a time just by adding the count (22
). With only maybe 100Mb you are probably better to just read the whole thing at once. $\endgroup$