Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a file with data in form {date, value}:
2010-05-19 17
2010-05-20 20
2010-05-21 19
...
How would I import such data in form {DateList, value}?

share|improve this question
    
Kudos for using the ISO 8601 standard date format. The Fred Flintstone Format (MM/DD/YY) should be banned! :-) –  stevenvh Oct 2 '12 at 10:16
    
@stevenvh as should be yards, inches and non-ISO units in general (my favorite is psi). –  Yves Klett Oct 2 '12 at 10:57

1 Answer 1

up vote 12 down vote accepted

Import[(* file *), "Table", "DateStringFormat" -> {"Year", "-", "Month", "-", "Day"}] seems to work...


As a test:

Export["test.dat",
       {{"2010-05-19", 17}, {"2010-05-20", 20}, {"2010-05-21", 19}},
       "FieldSeparators" -> " "];

Import["test.dat", "Table",
       "DateStringFormat" -> {"Year", "-", "Month", "-", "Day"}]
{{{2010, 5, 19}, 17}, {{2010, 5, 20}, 20}, {{2010, 5, 21}, 19}}
share|improve this answer
    
Beat me by a minute! –  Szabolcs Jan 29 '12 at 10:21
    
Can you fix up yours to explicitly show that it works on the sample data? Then I'll delete mine. –  Szabolcs Jan 29 '12 at 10:23
    
@J.M. It seems that no "-" is needed. Thanks. –  enedene Jan 29 '12 at 10:28
    
@Szabolcs, Done. –  J. M. Jan 29 '12 at 10:31
3  
@enedene: I wanted to show how to indicate delimiters explicitly, should you encounter a more peculiar date format. Replace the dashes accordingly in the code above. –  J. M. Jan 29 '12 at 10:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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