iode.Variables.df

property Variables.df: DataFrame

Create a pandas DataFrame from the current Variables database. The index of the returned DataFrame is build from the Variables names and the columns from the periods.

Warning

IODE and pandas don’t use the same constant to represent NaN values. When exporting IODE variables as a pandas DataFrame, the IODE NaN values (\(NA\)) are converted to pandas NaN values (\(nan\)).

Examples

>>> from iode import SAMPLE_DATA_DIR
>>> from iode import variables
>>> import pandas as pd
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> len(variables)
394
>>> variables.sample
Sample("1960Y1:2015Y1")
>>> variables.nb_periods
56
>>> # Export the IODE Variables database as a pandas DataFrame
>>> df = variables.df
>>> df.shape
(394, 56)
>>> df.index.to_list()
['ACAF', 'ACAG', 'AOUC', ..., 'ZKFO', 'ZX', 'ZZF_']
>>> df.columns.to_list()
['1960Y1', '1961Y1', ..., '2014Y1', '2015Y1']
>>> variables["AOUC"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL

name        1960Y1  1961Y1  ...  2014Y1   2015Y1
AOUC            na    0.25  ...    1.42     1.46

>>> df.loc["AOUC"]
time
1960Y1         NaN
1961Y1    0.247832
...
2014Y1    1.423714
2015Y1    1.460863
Name: AOUC, dtype: float64    
>>> variables["ZKFO"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL

name        1960Y1  1961Y1  ...  2014Y1   2015Y1
ZKFO          1.00    1.00  ...    1.02     1.02

>>> df.loc["ZKFO"]
time
1960Y1    1.00000
1961Y1    1.00000
...
2014Y1    1.01599
2015Y1    1.01599
Name: ZKFO, dtype: float64
>>> # Export a subset of the IODE Variables database as a pandas DataFrame
>>> df = variables["A*;*_"].df
>>> df.shape
(33, 56)
>>> df.index.to_list()
['ACAF', 'ACAG', 'AOUC', ..., 'WNF_', 'YDH_', 'ZZF_']
>>> df.columns.to_list()
['1960Y1', '1961Y1', ..., '2014Y1', '2015Y1']
>>> variables["AOUC"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL

name        1960Y1  1961Y1  ...  2014Y1   2015Y1
AOUC            na    0.25  ...    1.42     1.46

>>> df.loc["AOUC"]
time
1960Y1         NaN
1961Y1    0.247832
...
2014Y1    1.423714
2015Y1    1.460863
Name: AOUC, dtype: float64    
>>> variables["ZZF_"]
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL

name        1960Y1  1961Y1  ...  2014Y1   2015Y1
ZZF_          0.69    0.69  ...    0.69     0.69

>>> df.loc["ZZF_"]
time
1960Y1    0.6884
1961Y1    0.6884
...
2014Y1    0.6884
2015Y1    0.6884
Name: ZZF_, dtype: float64