Getting started with Italian data on COVID-19

(require '[panthera.panthera :as pt])
(require '[libpython-clj.python :refer [call-attr]])
17.2s
panthera (Clojure)
(defonce provinces-url 
  "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-province/dpc-covid19-ita-province.csv")
(defonce regions-url
  "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv")
0.0s
panthera (Clojure)
'user/regions-url
(def provinces
  (pt/read-csv provinces-url))
(def regions
   (pt/read-csv regions-url))
0.3s
panthera (Clojure)
'user/regions
(defn show
  [obj]
  (if (pt/series? obj)
  	{:nextjournal/viewer "html" 
     :nextjournal.viewer/value (call-attr (call-attr obj "to_frame") "to_html")}
    {:nextjournal/viewer "html" 
     :nextjournal.viewer/value (call-attr obj "to_html")}))
0.0s
panthera (Clojure)
'user/show
(show (pt/head provinces))
0.1s
panthera (Clojure)
(print (pt/names provinces))
0.5s
panthera (Clojure)
{"~#'":null}
(def mapper-provinces
  {:data :date
   :stato :state
   :codice_regione :region-code
   :denominazione_regione :region-name
   :codice_provincia :province-code
   :denominazione_provincia :province-name
   :sigla_provincia :province-abbreviation
   :lat :lat
   :long :lon
   :totale_casi :cases})
0.0s
panthera (Clojure)
'user/mapper-provinces
(show (pt/head (pt/rename provinces {:columns mapper-provinces})))
0.1s
panthera (Clojure)
(defn renamer
  [df mapper]
  (pt/rename df {:columns mapper}))
(def provinces-renamed
  (renamer provinces mapper-provinces))
0.0s
panthera (Clojure)
'user/provinces-renamed
(print (pt/unique (pt/subset-cols provinces-renamed :province-name)))
0.4s
panthera (Clojure)
(-> (pt/subset-cols provinces-renamed :province-name)
  pt/n-unique)
0.0s
panthera (Clojure)
108
(defn clean-data
  [df mapper]
  (as-> (renamer df mapper) d
        (pt/filter-rows d
          (pt/ne (pt/subset-cols d :province-name) 
            "In fase di definizione/aggiornamento"))))
0.0s
panthera (Clojure)
'user/clean-data
(show (pt/head (clean-data provinces mapper-provinces)))
0.1s
panthera (Clojure)
(print (pt/names regions))
0.5s
panthera (Clojure)
(def mapper-regions
  (merge 
    mapper-provinces
    {:ricoverati_con_sintomi :hospitalized
     :terapia_intensiva :icu
     :totale_ospedalizzati :tot-hospitalized
     :isolamento_domiciliare :quarantined
     :totale_attualmente_positivi :tot-positives
     :nuovi_attualmente_positivi :new-positives
     :dimessi_guariti :recovered
     :deceduti :dead
     :tamponi :tests}))
0.0s
panthera (Clojure)
'user/mapper-regions
(show (pt/head (renamer regions mapper-regions)))
0.1s
panthera (Clojure)
(pt/n-unique (pt/subset-cols regions :denominazione_regione))
0.0s
panthera (Clojure)
21
(print (pt/unique (pt/subset-cols regions :denominazione_regione)))
0.4s
panthera (Clojure)
(def regions-clean (renamer regions mapper-regions))
0.0s
panthera (Clojure)
'user/regions-clean
(-> regions (renamer mapper-regions) (pt/groupby [:date]) pt/sum pt/head show)
0.1s
panthera (Clojure)
(def regions-tests
  (-> (pt/subset-cols regions-clean :date :tests :new-positives)
      (pt/groupby :date)
      pt/sum))
0.0s
panthera (Clojure)
'user/regions-tests
(print (pt/shape regions-tests))
0.6s
panthera (Clojure)
(defn daily-tests []
  (-> regions-tests
    (pt/subset-cols :tests)
    pt/diff
    (pt/fill-na (first (pt/values (pt/subset-cols (pt/subset-rows regions-tests 1) :tests))))))
0.0s
panthera (Clojure)
'user/daily-tests
(print (pt/shape (daily-tests)))
0.5s
panthera (Clojure)
(first (pt/values (pt/subset-cols (pt/subset-rows regions-tests 1) :tests)))
(-> (pt/subset-rows regions-tests 1) (pt/subset-cols :tests) pt/values first)
0.0s
panthera (Clojure)
4324
(as-> regions-tests r 
  (pt/assign r {:daily-tests (daily-tests)}) 
  (pt/assign r {:new-by-test (pt/div (pt/subset-cols r :new-positives) (pt/subset-cols r :daily-tests))})
  (pt/shape r)
  (print r))
0.5s
panthera (Clojure)
(def r (pt/assign regions-tests {:daily-tests (daily-tests)}))
0.0s
panthera (Clojure)
'user/r
Shift+Enter to run
panthera (Clojure)
Runtimes (1)