I’m loading different indicator CSV files into JavaScript, example:
CSV for population:
id,year,value
AF,1800,3280000
AF,1820,3280000
AF,1870,4207000
AG,1800,37000
AG,1851,37000
AG,1861,37000
For each indicator file I need to:
- Gap fill missing years for each entity (id)
- Find the time span for each entity
- Find the min and max for each entity
- Find the time span for the indicator
- Find the min and max for the indicator
What is an inexpensive way of performing these operations? Alternatively, is there a good JavaScript library for performing these kind of common data operations and storing the data effectively in various object representations?
I’d like the final representation of the above file to look something like:
data = {
population : {
entities :
AF : {
data : {
1800 : 3280000,
1801 : 3280000,
},
entity_meta : {
start : 1800,
end :
min :
max :
},
[...]
indicator_meta : {
start : 1700,
end :
min :
max :
}
[...]
Thanks!
Lets Assume that you have the CSV data in a 2d array:
For this example I will use jQuerys utility functions as it will make the job a lot easier without any real overhead.
That obviously isn’t all the code but it should explain clearly the approach that should be taken.
Also not that your intended final object structure is very much over complicated you should really use arrays where appropriate, especially for
entitiesanddata.