Message Boards Message Boards


Plot regional data from by-country indicators?

Posted 6 months ago
3 Replies
0 Total Likes


I have a csv containing columns for countries, indicator name (e.g. population, fertility), and several columns for values on different years, such as a column for 1960, another for 1961, etc.

How do I create a listplot for regional data (grouping countries) taking the indicator of each country, calculculating a weighted average by population.

Below the example

Any help would be highly appreciated as my table is huge and have to create dozens of similar charts.

s = Import[
   "C:\\Users\\Jesus Enrique\\Documents\\Wolfram \
3 Replies
Posted 6 months ago

Hi Enrique,

Can you please attach the CSV?

Posted 6 months ago

Hi, done, file attached.

Hi Enrique,

you can begin in a very straightforward manner like so:

data0 = Import["sample1.csv", "CSV"];    
years = DateObject[{#}] & /@ data0[[1, -4 ;;]];
data1 = Association[#1[[1]] -> <|#1[[2]] -> <|Thread[Rule[years, #1[[3 ;;]]]]|>, #2[[2]] -> <|Thread[Rule[years, #2[[3 ;;]]]]|>|> & @@@ Partition[Rest[data0], 2]];
ds = Dataset[data1];

In this nice form of a Dataset one has a very direct access to every single element, e.g.:

yr = Key@*DateObject@*List;
ds["Algeria", "Population", yr@1961]

and the overall picture can be made visible easily, e.g.

enter image description here

As for a start I hope that helps, regards -- Henrik

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract