MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Converting date strings to DateList format - a need

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106545] Re: [mg106507] Converting date strings to DateList format - a need
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 15 Jan 2010 07:08:20 -0500 (EST)
  • Reply-to: hanlonr at cox.net

dataFile = {{"DATES", "DATA1", "DATA2"}, {"12/31/84", 1, 1}, {"01/01/85", 1, 
    1.00239}, {"01/02/85", 0.999206, 1.00238}, {"01/03/85", 0.997425, 
    1.00238}, {"01/04/85", 0.997038, 1.00237}, {"01/07/85", 0.989256, 
    1.0071}, {"01/08/85", 1.00867, 1.00235}, {"01/09/85", 0.994708, 
    1.00235}, {"01/10/85", 1.00552, 1.00234}};

Lengthen the data for timing

dataFile2 = Join[{dataFile[[1]]}, Sequence @@ Table[Rest[dataFile], {75}]];

t1 = Timing[dates =
     DateList[{#, {"Month", "Day", 
          "YearShort"}}] & /@
      (DateString[#] & /@
        Rest[dataFile2][[All, 1]]);][[1]]

2.69932

You have an unnecessary step; however, it doesn't slow it much.

t2 = Timing[dates2 =
     DateList[{#, {"Month", "Day", "YearShort"}}] & /@
      Rest[dataFile2[[All, 1]]];][[1]]

2.66548

Your date format is the default and it goes faster if you let it just use the default. 
Quiet is used to stop the warnings about the dates being ambiguous.

t3 = Timing[dates3 =
     Quiet[DateList[#] & /@
       Rest[dataFile2[[All, 1]]]];][[1]]

1.45169

The results are the same

dates == dates2 == dates3

True

{t2, t3}/t1

{0.987466,0.537798}


Bob Hanlon

---- Garapata <warsaw95826 at mypacks.net> wrote: 

=============
I have dates in the first column of large flat files (6000+ rows).
The flat files have a header row and may have as many as 20 columns of
data besides the dates.  A sample of a flat file follows

dataFile = {{"DATES", "DATA1", "DATA2"}, {"12/31/84", 1, 1},
{"01/01/85", 1,
  1.00239}, {"01/02/85", 0.999206, 1.00238}, {"01/03/85", 0.997425,
  1.00238}, {"01/04/85", 0.997038, 1.00237}, {"01/07/85", 0.989256,
  1.0071}, {"01/08/85", 1.00867, 1.00235}, {"01/09/85", 0.994708,
  1.00235}, {"01/10/85", 1.00552, 1.00234}}

I want to make a list of just the dates from the first column and turn
them into an unambiguous DataList[] format for later processing.

This works:

dates = DateList[{#, {"Month", "Day","YearShort"}}] & /@ (DateString
[#] & /@Rest[dataFile][[All, 1]]);

but, with thousands of dates in a file to convert, it takes a long
time to run.  The Map within a Map seems to slow things down a lot.
Unless I've missed something, (quite possible) neither DateList[] nor
DateString seem to operate directly on lists, so I haven't figured out
a better way to do this.

Can I do anything to make this run faster?  Any solutions much
appreciated.




  • Prev by Date: Re: Converting date strings to DateList format - a need for speed
  • Next by Date: Re: Question about Mathematica
  • Previous by thread: Re: Re: Question about Mathematica
  • Next by thread: AstronomicalData - solar ecliptic longitude