Message Boards Message Boards

Plot regional data from by-country indicators?

Posted 6 years ago

Hi,

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 \
Desktop\\Sample1.csv"];
Attachments:
POSTED BY: Enrique Vargas
3 Replies

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
Posted 6 years ago

Hi Enrique,

Can you please attach the CSV?

POSTED BY: Sean Cheren
Posted 6 years ago

Hi, done, file attached.

POSTED BY: Enrique Vargas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract