Interactive online version: Binder badge

Compatibility with pandas

Import the LArray library:

[1]:
from larray import *

To convert an Array object into a pandas DataFrame, the method to_frame() can be used:

[2]:
population = load_example_data('demography_eurostat').population
population
[2]:
country  gender\time      2013      2014      2015      2016      2017
Belgium         Male   5472856   5493792   5524068   5569264   5589272
Belgium       Female   5665118   5687048   5713206   5741853   5762455
 France         Male  31772665  32045129  32174258  32247386  32318973
 France       Female  33827685  34120851  34283895  34391005  34485148
Germany         Male  39380976  39556923  39835457  40514123  40697118
Germany       Female  41142770  41210540  41362080  41661561  41824535
[3]:
df = population.to_frame()
df
[3]:
time 2013 2014 2015 2016 2017
country gender
Belgium Male 5472856 5493792 5524068 5569264 5589272
Female 5665118 5687048 5713206 5741853 5762455
France Male 31772665 32045129 32174258 32247386 32318973
Female 33827685 34120851 34283895 34391005 34485148
Germany Male 39380976 39556923 39835457 40514123 40697118
Female 41142770 41210540 41362080 41661561 41824535

Inversely, to convert a DataFrame into an Array object, use the function asarray():

[4]:
population = asarray(df)
population
[4]:
country  gender\time      2013      2014      2015      2016      2017
Belgium         Male   5472856   5493792   5524068   5569264   5589272
Belgium       Female   5665118   5687048   5713206   5741853   5762455
 France         Male  31772665  32045129  32174258  32247386  32318973
 France       Female  33827685  34120851  34283895  34391005  34485148
Germany         Male  39380976  39556923  39835457  40514123  40697118
Germany       Female  41142770  41210540  41362080  41661561  41824535