4
$\begingroup$

This link https://www.worldometers.info/coronavirus/ provides daily cases of COVID-19 across all the countries. Is there an easy way to retrieve this table into a Mathematica notebook?

I tried:

Import["https://www.worldometers.info/coronavirus/", "HTML"]

which retrieves the data in an unformatted structure.

Thanks.

$\endgroup$
2
  • 4
    $\begingroup$ Consider using another source with friendlier formatting, such as the European Centre for Disease Control and Prevention's data set, which is available as CSV, XLM, or JSON; or the database maintained by Our World in Data, which is explicitly freely available in various formats as well. $\endgroup$ – MarcoB Nov 27 '20 at 19:26
  • $\begingroup$ @MarcoB: I tried to import the data for a selected set of countries using MMA but the results are not so impressive because there are many text I am not interested in. I have a list of countries {Turkey, USA, China} for which I like to retrieve the data for several variables: {Total Cases, New Cases, Total Deaths, Total Recovered, Population}. How can I create this table using MMA code? $\endgroup$ – Tugrul Temel Nov 27 '20 at 20:28
5
$\begingroup$

( Not an answer, extended comment.)

In this particular case (the code of that site today):

lsData = Import["https://www.worldometers.info/coronavirus", "Data"]

works. Meaning, the data can be investigated further using Cases, Part, and TableForm (or other tabular formatting function.)

enter image description here

For example, this list

lsTbls = Cases[
   lsData, {{"#", "Country, Other", "Total Cases", "New Cases", 
     "Total Deaths", ___}, ___}, \[Infinity]];
Length[lsTbls]

(* 3 *)

has three elements that (seem to) correspond to "Now", "Yesterday", "2 days ago" shown in the site.

Note, the data has a continent column, but the import above did not align the rows/columns properly. Meaning, further data massaging / wrangling is needed.

$\endgroup$
2
$\begingroup$

Read the data not with "HTML" but with "Data":

dat = Import["https://www.worldometers.info/coronavirus/", "Data"];

Now you have all data in one big mess and you need to pick it apart.

E.g.:

TableForm[tt[[2, 2, 2, 1, 2]], TableHeadings -> {None, tt[[2, 2, 2, 1, 1]]}]

Or:

TableForm[tt[[2, 2, 2, 2, 2]], TableHeadings -> {None, tt[[2, 2, 2, 2, 1]]}]

E.t.c.

$\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.