Message Boards Message Boards

Plot regional data from by-country indicators?



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 \
POSTED BY: Enrique Vargas
8 days ago

Hi Enrique,

Can you please attach the CSV?

POSTED BY: Sean Cheren
5 days ago

Hi, done, file attached.

POSTED BY: Enrique Vargas
4 days ago

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

POSTED BY: Henrik Schachner
3 days ago

Group Abstract Group Abstract