2
$\begingroup$

I am importing a CSV file that looks like this (Extract of data as viewed in Notepad):

"DateObject[{2022, 4, 11, 7, 0, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.27727296
"DateObject[{2022, 4, 11, 7, 1, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.40909108
"DateObject[{2022, 4, 11, 7, 2, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.40909113

I want to plot this data using DateListPlot, but as it is it doesn't seem to know how to understand the date-time coordinate values.

I get the following error:

DateListPlot::dtvals: Unable to automatically determine horizontal coordinates for the given data and DataRange.


Just a clarification that this is what the data file looks like when viewed in Excel:

enter image description here

$\endgroup$
5
  • $\begingroup$ I get the following error: DateListPlot::dtvals: Unable to automatically determine horizontal coordinates for the given data and DataRange. $\endgroup$
    – Richard
    May 19 at 14:49
  • $\begingroup$ Thi is what the data looks like in Notepad:"DateObject[{2022, 4, 11, 7, 0, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.27727296 "DateObject[{2022, 4, 11, 7, 1, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.40909108 "DateObject[{2022, 4, 11, 7, 2, 0.}, ""Instant"", ""Gregorian"", 1.]",-12.40909113 $\endgroup$
    – Richard
    May 19 at 15:32
  • $\begingroup$ @rhermans yes that works! I've been banging my head on my desk all afternoon over this $\endgroup$
    – Richard
    May 19 at 15:54
  • $\begingroup$ Ok, let's learn from the experience. This was unnecessarily complicated because you didn't share all the necessary information from the beginning. Next time, please take some time to prepare all the information we can need and present it in a way that is easy for us to read. I have edited your question to a more desirable format. $\endgroup$
    – rhermans
    May 19 at 16:01
  • $\begingroup$ Let's delete the comments that are now obsolete so the question can be useful to other people in the future. Also, @Richard, please follow the tour, you will get a new badge and learn more about how to participate better on this site. $\endgroup$
    – rhermans
    May 19 at 16:07

1 Answer 1

4
$\begingroup$

You have a String representation of a Mathematica expression, you can transform it using ToExpression. To apply this only to the relevant column you can use MapAt like this

DateListPlot@MapAt[ToExpression,  Import[filepath,"CSV"],{All,1}]

Other solutions exist, I will leave it for other members of the community to add better alternatives.

enter image description here

$\endgroup$

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.