I need to take data from a CSV file and attach it to the main JSON I use for my Angular app.
More specifically, I need to take the life expectancies from the CSV file and attach them to the matching country of the JSON (the JSON data is an array of objects, of length 212 and the CSV data is of length 200).
I use d3.js to parse the CSV file. I tried this but it doesn't seem to work. The getData method that I subscribe, is the main source of data, in which I want to attach life expectancy.
this.store.getData().subscribe((data: Data[]) => {
d3.csv('../assets/datasets/life_expectancy.csv').then((csvData: any) => {
for (let i = 0; i < csvData.length; i++) {
if (csvData[i].country_name === data[i].country) {
data[i].lifeExpectancy = csvData[i].country_life_expectancy;
}
}
});
The life expectancy CSV is like this ([{country_name: 'United States', {country_life_expextancy: 79.11}}...])