Published
Edited
Mar 2, 2020
1 star
Insert cell
Insert cell
Insert cell
coronaConfirmedRawDataAttempt1 = d3.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
Insert cell
Insert cell
coronaConfirmedRawData = d3.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv",d3.autoType)
Insert cell
Insert cell
Insert cell
coronaConfirmedValues = Object.keys(coronaConfirmedRawData).map( k => coronaConfirmedRawData[k] )
Insert cell
md`# Let's just get ONE record, and see if we can transform it....`
Insert cell
Insert cell
Insert cell
{Lat, Long, ...rest} = coronaConfirmedRawData1
Insert cell
Insert cell
(({Lat, Long}) => ({Lat, Long}))(coronaConfirmedRawData1)
Insert cell
Insert cell
(({Province/State,Lat, Long}) => ({Province/State,Lat, Long}))(coronaConfirmedRawData1)
Insert cell
Insert cell
(({"Province/State",Lat, Long}) => ({"Province/State",Lat, Long}))(coronaConfirmedRawData1)
Insert cell
md`I guess you can't do destructuring on non-variable-name-compliant keys.`
Insert cell
Insert cell
Object.keys(coronaConfirmedRawData1).slice(4)
Insert cell
Insert cell
Object.keys(coronaConfirmedRawData1).slice(4).map(d => ({
key: d,
date: d.replace(/(\d+)\/(\d+)\/(\d+)/,"20$3-$1-$2")
}))
Insert cell
Insert cell
Object.keys(coronaConfirmedRawData1).slice(4).map(d => d.replace(/(\d+)\/(\d+)\/(\d+)/,"20$3-$1-$2"))
Insert cell
md`# Use new Date(d)`
Insert cell
Object.keys(coronaConfirmedRawData1).slice(4).map(d => new Date(d))
Insert cell
Insert cell
Insert cell
{
let result = [];
const ProvinceOrState = coronaConfirmedRawData1["Province/State"];
const CountryOrRegion = coronaConfirmedRawData1["Country/Region"];
const Lat = coronaConfirmedRawData1.Lat;
const Long = coronaConfirmedRawData1.Long
for(let k in coronaConfirmedRawData1) {
if(k.match(/\d+\/\d+\/\d+/)) {
result.push(
({
ProvinceOrState:ProvinceOrState,
CountryOrRegion:CountryOrRegion,
Lat:Lat,
Long:Long,
Occurence:coronaConfirmedRawData1[k],
Date:new Date(k)
})
)
}
}
return result
}
Insert cell
Insert cell
dataToTable = d => {
let result = [];
const ProvinceOrState = d["Province/State"];
const CountryOrRegion = d["Country/Region"];
const Lat = d.Lat;
const Long = d.Long
return Object.keys(d).slice(4).map(k => ({
ProvinceOrState:ProvinceOrState,
CountryOrRegion:CountryOrRegion,
Lat:Lat,
Long:Long,
Occurence:d[k],
Date:new Date(k)
})
)
}
Insert cell
Insert cell
Insert cell
Insert cell
coronaConfirmedTable = coronaConfirmedRawData.reduce( (r,d) => r.concat( dataToTable( d ) ) , [] )
Insert cell
Insert cell
d3 = require("d3@5", "d3-sankey@0.12")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more