-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin.js
62 lines (53 loc) · 1.61 KB
/
join.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const aq = require('arquero')
const fs = require('fs-extra')
const path = require('path')
const d3 = require('d3')
async function loading() {
console.log('---> start processing')
//Loading data
const data = await aq.load(
`../js/output_data/tidy_data.csv`,
{ delimiter: ',' },
{ using: aq.fromCSV }
)
// console.log(data.objects());
//Loading info
const WID_countries = await aq.load(
`../data/WID_countries.csv`,
{ delimiter: ',' },
{ using: aq.fromCSV }
)
// console.log(WID_countries.objects());
//Join data and info
let data_all = data
.join(WID_countries, ['country', 'alpha2'])
.select(
'year',
'country',
'gdiincj992',
'gptincj992',
'rdiincj992',
'rptincj992',
'region',
'region2',
'shortname'
)
.rename({
gptincj992: 'gini_pretaxes',
gdiincj992: 'gini_posttaxes',
rdiincj992: 'ratio1050_posttaxes',
rptincj992: 'ratio1050_pertaxes',
})
.derive({ decade: (d) => Math.floor(d.year / 10) * 10 })
.objects()
console.log(data_all)
const csvData = d3.csvFormat(data_all)
// console.log(csvData);
//Write CSV data to file
const outputPath = path.resolve(__dirname, './output_data/data_all.csv')
fs.ensureDirSync(path.dirname(outputPath))
fs.writeFileSync(outputPath, csvData, 'utf8')
console.log(`CSV file has been written to ${outputPath}`)
console.log('<--- finsished processing')
}
loading()