I have a text file with two columns containing space-delimited numeric data. The data are divided into segments, where each of them contains a variable number of rows and the beginning of the next segment is indicated by a single row of NaN
(so the data below would be comprised of four segments):
5.1
[space] 0.0
9.2
[space] 1.4
3.7
[space] 0.6
...
[space] ...
...
[space] ...
...
[space] ...
NaN
[space] NaN
9.7
[space] 6.3
1.4
[space] 1.0
...
[space] ...
...
[space] ...
NaN
[space] NaN
8.7
[space] 0.0
5.1
[space] 7.4
3.7
[space] 2.6
...
[space] ...
NaN
[space] NaN
1.7
[space] 8.4
...
[space] ...
and so forth...
Now I'd like to generate a plot displaying a curve for each data segment in the file (by plotting each segments 1st
column against its 2nd
column).
I know how to do this if
the number of rows in each segment is the same and
the number of segments is known.
How can that be done efficiently when there's a variable segment size and an unknown number of segments?