I have a large data file (150 000 lines) which I want to import in Mathematica. The first few lines look like this
28/04/2013 20:01:36.18 2.5013E-2 W
28/04/2013 20:01:36.26 2.5013E-2 W
28/04/2013 20:01:36.32 2.5013E-2 W
28/04/2013 20:01:36.35 2.5011E-2 W
28/04/2013 20:01:36.48 2.5011E-2 W
28/04/2013 20:01:36.53 2.5011E-2 W
28/04/2013 20:01:36.60 2.5008E-2 W
28/04/2013 20:01:36.64 2.5008E-2 W
28/04/2013 20:01:36.70 2.5008E-2 W
The first column is the date, second is the time, third is the measured value and the last is the unit of measurements.
I want to make ListPlot
of the data, where the x axis should be time since the start in proper formatting (e. g. HH:MM) and the y axis the measured value. Of course, the importing has to be done very efficiently, due to the large number of lines. So, I guess I should use ReadList, but I don't know how to Mathematica what I want.
Update in response of the comments below
I used this code
s = OpenRead["filename.dat"];
data = ReadList[s, {Record, Number, Record}, RecordSeparators -> {"\t","\n"}]
which gives me this
{{"28/04/2013 20:01:36.18", 0.025013, "W"},
{"28/04/2013 20:01:36.26", 0.025013, "W"},
{"28/04/2013 20:01:36.32", 0.025013, "W"}....}
Now, the problem is how to plot this the way I want.
s = OpenRead["data.txt"]
, and read in every line as a string,ReadList[s, Record]
, yes? $\endgroup$DateList
. With that result you can then use e.g.DateListPlot
. As converting withDateList
might be relatively slow and your date format is fixed, I would suggest to use aStringReplace
+ToExpression
approach for improved performance. I think answers to this question will also be relevant, although your file seems to rather be large but not yet huge. $\endgroup$Downsample
is a possibility. $\endgroup$Joined->True
, so that is not a problem, but thanks for the tip $\endgroup$Joined
isn't really a solution. My point was that if you have 150,000 points or line segments, the screen won't be able to show them all, so this kind of input is a bit of overkill. $\endgroup$