Import the LArray library:
In [ ]:
from larray import *
Load the population array and related axes from the demography_eurostat dataset:
In [ ]:
# load the 'demography_eurostat' dataset
demography_eurostat = load_example_data('demography_eurostat')
# extract the 'country', 'gender' and 'time' axes
country = demography_eurostat.country
gender = demography_eurostat.gender
time = demography_eurostat.time
# extract the 'population_5_countries' array as 'population'
population = demography_eurostat.population_5_countries
# show the 'population' array
population
The LArray library provides many aggregation functions. The list is given in the Aggregation Functions subsection of the API Reference page.
Aggregation operations can be performed on axes or groups. Axes and groups can be mixed.
The main rules are:
,Calculate the sum along an axis:
In [ ]:
population.sum(gender)
or several axes (axes are separated by commas ,):
In [ ]:
population.sum(country, gender)
Calculate the sum along all axes except one by appending _by to the aggregation function:
In [ ]:
population.sum_by(time)
Calculate the sum along groups (the groups belonging to the same axis must grouped inside parentheses ()):
In [ ]:
benelux = population.country['Belgium', 'Netherlands', 'Luxembourg'] >> 'benelux'
fr_de = population.country['France', 'Germany'] >> 'FR+DE'
population.sum((benelux, fr_de))
Mixing axes and groups in aggregations:
In [ ]:
population.sum(gender, (benelux, fr_de))