Compatibility with pandas¶
To convert a LArray object into a pandas DataFrame, the method to_frame()
can be used:
In [1]: df = pop.to_frame()
In [2]: df
Out[2]:
year 2015 2016 2017
age sex
0-9 F 0.0 0.0 0.0
M 0.0 0.0 0.0
10-17 F 0.0 0.0 0.0
M 0.0 0.0 0.0
18-66 F 0.0 0.0 0.0
M 0.0 0.0 0.0
67+ F 0.0 0.0 0.0
M 0.0 0.0 0.0
Inversely, to convert a DataFrame into a LArray object, use the function aslarray()
:
In [3]: pop = aslarray(df)
In [4]: pop
Out[4]:
age sex\year 2015 2016 2017
0-9 F 0.0 0.0 0.0
0-9 M 0.0 0.0 0.0
10-17 F 0.0 0.0 0.0
10-17 M 0.0 0.0 0.0
18-66 F 0.0 0.0 0.0
18-66 M 0.0 0.0 0.0
67+ F 0.0 0.0 0.0
67+ M 0.0 0.0 0.0