Message Boards Message Boards

0
|
3531 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

TimeLinePlot: Better way to get the data?

Posted 3 years ago

I'm a dabbler, no master and figure there have to be a better way too do this.

I want to show how long it has taken to get to the next million cases of COVID in the US.

I can get the data and get the result am looking for, but it feels like I'm doing it the hard way. How could I do this so I get a TimeLinePlot, but do not have to add each Select individually?

ndata = Total[
Normal@ResourceData[
"Epidemic Data for Novel Coronavirus COVID-19"][
Select[MatchQ[Entity["Country", "UnitedStates"], #Country] && ! 
MissingQ[#AdministrativeDivision] &]][
All, #ConfirmedCases &]];

 ntl = Take[
       Transpose[
        Flatten[{Take [Select[Normal[ndata], Last[#] < 1000000 &], -1], 
          Take [Select[Normal[ndata], Last[#] < 2000000 &], -1], 
          Take [Select[Normal[ndata], Last[#] < 3000000 &], -1], 
          Take [Select[Normal[ndata], Last[#] < 4000000 &], -1]}, 1]], 1];

TimelinePlot[ntl]
POSTED BY: Michael Madsen
3 Replies
Posted 3 years ago

Michael:

I think I figured out how to get the data given a list of countries:

covidData = 
  ResourceData["Epidemic Data for Novel Coronavirus COVID-19"];
getData[country_String] := 
  Normal@covidData[
    Select[MatchQ[Entity["Country", country], #Country] && ! 
        MissingQ[#AdministrativeDivision] &], "ConfirmedCases"];

ndata = 
  Map[
     getData,
     {"UnitedStates", "Canada", "UnitedKingdom}
     ]  // Flatten // Total;

But I am still learning about TimeSeries. And can't figure out how to use what is returned. I think I am close, but I have run out of time.

I hope this helps.

Have a great and safe weekend.

POSTED BY: Mike Besso
Posted 3 years ago

Hi Michael,

Here is one way to do it.

BlockMap[(If[
      Floor[Last@Last@#, 10^6] - Floor[Last@First@#, 10^6] >= 10^6, 
      First@First@#, Nothing] &), ndata // Normal, 2, 1] //  
Flatten //
TimelinePlot

enter image description here

POSTED BY: Rohit Namjoshi
Posted 3 years ago

That works. I'm not sure how, but it does. Thanks.

POSTED BY: Michael Madsen
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract