0
$\begingroup$

I'm trying to experiment with the covid-19 data from John Hopkins as a way of learning some basic Mathematica functionality. I pulled down the CSV files and figured out how to convert them to datasets and then extra particular rows, etc. I ended up with a small chunk of data covering part of January and February. If I use DateListPlot on the first portion of that data, just covering January, it works fine. However, if I increase the length of the data by just 1 such that the first date of February is included, I get the following error:

DateListPlot::ldata: <|1/22/20->2,1/23/20->1,1/24/20->2,1/25/20->2,1/26/20->4,1/27/20->4,1/28/20->7,1/29/20->7,1/30/20->11,1/31/20->15,2/1/20->20|> is not a valid dataset or list of datasets.

I have no idea why adding the first date of the next month produces this error and would appreciate any insights.

Thanks in advance


Here is what I did

1) Pulled down the data from Github (https://github.com/CSSEGISandData/COVID-19.git)

Then in a Notebook:

confirmed = 
  Import["/Volumes/HD2/Github/COVID-19/csse_covid_19_data/csse_covid_\19_time_series/time_series_19-covid-Confirmed.csv", "Dataset",    "HeaderLines" -> 1];

(* See first image -- the plot works when the range goes from 5 to 14 but as soon as I change the end index from 14 to 15, the plot fails even though the list data displays correctly *)

enter image description here

enter image description here

$\endgroup$
5
  • $\begingroup$ This is based on John Hopkins and might bee easier for you. Also see wolfr.am/coronavirus . $\endgroup$ Mar 20 '20 at 6:23
  • $\begingroup$ Yes, thanks - I saw that --- however, I wanted to use the raw data from github as an excuse to teach myself some basic Mathematica. I'm mostly having problems with syntax. But this bizarre error about the dataset not being valid only when I add an extra date to it is throwing me. $\endgroup$
    – David
    Mar 20 '20 at 12:38
  • $\begingroup$ you should provide more detail: both inputs working and non working and screenshots of outputs for both of them for people to be able to explain to you what is going on. $\endgroup$ Mar 20 '20 at 14:30
  • $\begingroup$ I have updated the initial post with some images that should clarify what I did. Really appreciate the help. $\endgroup$
    – David
    Mar 20 '20 at 17:57
  • $\begingroup$ I have updated my answer. $\endgroup$ Mar 20 '20 at 18:16
2
$\begingroup$

It is clear now that the extra point that you add is the only one that has the date that is ambiguous to interpretation:

data=Normal[confirmed[1][[5;;15]]]

<|"1/22/20" -> 2, "1/23/20" -> 3, "1/24/20" -> 5, "1/25/20" -> 7, "1/26/20" -> 8, "1/27/20" -> 8, "1/28/20" -> 14, "1/29/20" -> 14, "1/30/20" -> 14, "1/31/20" -> 19, "2/1/20" -> 19|>

So the last point -- is it FEB 1 or JAN 2 ? DateListPlot cannot interpret that date and gives error. This is why you need exact interpretation of dates:

convert=KeyMap[DateObject[{#,{"Month","Day","YearShort"}}]&,data]

enter image description here

Now it obviously works, no errors:

DateListPlot[convert, PlotMarkers -> Automatic]

enter image description here

$\endgroup$
7
  • $\begingroup$ I'll try quotes but I don't understand then why it works for the January dates and only fails when I start to include Feb dates. $\endgroup$
    – David
    Mar 20 '20 at 12:35
  • $\begingroup$ If the "/" was computing division, then why does it work fine if I just use the january dates, e.g, that exact dataset you saw above with the very last item missing? $\endgroup$
    – David
    Mar 20 '20 at 13:07
  • $\begingroup$ @David you should provide more detail: both inputs working and non working and screenshots of outputs for both of them for people to be able to explain to you what is going on. $\endgroup$ Mar 20 '20 at 13:35
  • $\begingroup$ @David ...and are you sure "it work fine" ? Do you see the same horizontal axis time stamps as on my plot? $\endgroup$ Mar 20 '20 at 15:01
  • $\begingroup$ Yes, look at my first graph- it has the correct values for both dates (X-axis) and quantities (Y-axis) $\endgroup$
    – David
    Mar 20 '20 at 19:39

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.