-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_wrangling.html
More file actions
executable file
·48 lines (42 loc) · 1.55 KB
/
Copy pathdata_wrangling.html
File metadata and controls
executable file
·48 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="../libs/FileSaver.js"></script>
<script>
var saveToFile = function(object, filename) {
var blob, blobText;
blobText = [JSON.stringify(object)];
blob = new Blob(blobText, {
type : "text/plain;charset=utf-8"
});
saveAs(blob, filename);
}
// convert csv to json format for better machine readability
var json = {}
d3.csv("./data/CountryData.csv", function(data) {
// utils
data.map(function(row) {
if (json[row.Country] == null) {
json[row.Country] = {}
}
json[row.Country][row.Variable] = {}
var dates = d3.keys(row).filter(function(k) {
return k != 'Country' && k != 'Variable'
}).filter(function(k) {
return row[k] != ""
}).map(function(k) {
return json[row.Country][row.Variable][k] = row[k]
})
})
// save the json file
saveToFile(json, 'data.json')
})
</script>
</body>
</html>