3
$\begingroup$

I'm trying to import CSV file with the following format:

20150803 00:00:01.649,1.09675,1.09678

using this code:

Import[filename, 
  "DateStringFormat" -> {"Year", "Month", "Day", " ", "Hour", ":", 
    "Minute", ":", "Second", ".", "Millisecond"}]

But this does not import Time part - it only imports the Date:

{{DateObject[{2015, 8, 4}], 1.09675, 1.09682}, 
 {DateObject[{2015, 8, 3}], 1.09675, 1.09678},
 ...

How can I import all of the information from my file?

$\endgroup$
2
$\begingroup$

Import does not support the time portion of DateStringFormat. (This is a deficiency in the docs if not a bug ) If you know the specific column(s) where your date appears you can map datelist like this:

MapAt[DateList[{#, {"Year", "Month", "Day", " ", "Hour", ":", 
 "Minute", ":", "Second", ".", "Millisecond"}}] & , 
      Import[filename.csv], {All, 1}]

In case you do not know where the strings might occur you can do this:

Map[Quiet@
  Check[DateList[{#, {"Year", "Month", "Day", " ", "Hour", ":", 
    "Minute", ":", "Second", ".", "Millisecond"}}], #] & , 
       Import[filename.csv], {-1}]

I would guess this will really kill performance on a large file though.

$\endgroup$
0
$\begingroup$

I found solution at this answer:

And also improved loading speed of my 250Mb CSV file

$\endgroup$
  • $\begingroup$ 250 Gb, would that mean Giga-Bit or was it a type and would read like GB (Giga-Byte) or are it rather Mega-Bytes really? I would wonder on what machine Mathematica would be able to handle a 250 Gb (30GB ?) CSV file :-) $\endgroup$ – Albert Retey Sep 17 '15 at 14:31
  • $\begingroup$ Oh, I'm mistaked - my CSV file 250Mb, not 250Gb :) $\endgroup$ – Slava Bogdanov Sep 19 '15 at 11:23
  • $\begingroup$ OK, that sounds somewhat less demanding :-) $\endgroup$ – Albert Retey Sep 19 '15 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.