IODE and pandas
IODE offers many ways to interact with pandas Series and DataFrame objects.
Lets start with necessary imports and loading the sample data:
[1]:
import numpy as np
import pandas as pd
from iode import (SAMPLE_DATA_DIR, comments, equations, identities, lists, scalars,
tables, variables, Sample, NA)
[2]:
# ---- load equations, identities, scalars and variables ----
# Note: test binary and ASCII 'fun' files are located in the 'SAMPLE_DATA_DIR'
# directory of the 'iode' package
comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs")
identities.load(f"{SAMPLE_DATA_DIR}/fun.idt")
lists.load(f"{SAMPLE_DATA_DIR}/fun.lst")
scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl")
tables.load(f"{SAMPLE_DATA_DIR}/fun.tbl")
variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
# ---- print the number of objects present in the above workspaces ----
len(comments), len(equations), len(identities), len(lists), len(scalars), len(tables), len(variables)
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.cmt
317 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.eqs
274 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.idt
48 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.lst
17 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.scl
161 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.tbl
46 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.var
394 objects loaded
[2]:
(317, 274, 48, 17, 161, 46, 394)
Update multiple IODE objects at once
Using pandas Series and DataFrame objects, you can update multiple IODE objects at once.
Comments
[3]:
# 2) using a pandas series
data = ["Updated AOUC from series", "Updated ACAF from series", "Updated ACAG from series"]
series = pd.Series(data, index=["AOUC", "ACAF", "ACAG"])
comments["ACAF, ACAG, AOUC"] = series
comments["ACAF, ACAG, AOUC"]
[3]:
Workspace: Comments
nb comments: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.cmt
name comments
ACAF Updated ACAF from series
ACAG Updated ACAG from series
AOUC Updated AOUC from series
Identities
[4]:
# using a pandas series
data = ["0.8 * 100*(QAFF_/(Q_F+Q_I))", "0.8 * 100*((QAF_/Q_F)-1)", "0.8 * (GOSF/VAF_)"]
series = pd.Series(data, index=["GAP2", "GAP_", "GOSFR"])
identities["GAP2, GAP_, GOSFR"] = series
identities["GAP2, GAP_, GOSFR"]
[4]:
Workspace: Identities
nb identities: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.idt
name identities
GAP2 0.8 * 100*(QAFF_/(Q_F+Q_I))
GAP_ 0.8 * 100*((QAF_/Q_F)-1)
GOSFR 0.8 * (GOSF/VAF_)
Equations
[5]:
# using a pandas DataFrame
data = []
data.append(["ACAF", "(ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+ acaf4*(TIME=1995)", "GLS", '1980Y1:1996Y1'])
data.append(["ACAG", "ACAG := ACAG[-1]+r VBBP[-1]+(0.006*VBBP[-1]*(TIME=2001)-0.008*(TIME=2008))", "GLS", '1980Y1:1996Y1'])
data.append(["AOUC", "AOUC:=((WCRH/QL)/(WCRH/QL)[1990Y1])*(VAFF/(VM+VAFF))[-1]+PM*(VM/(VAFF+VM))[-1]", "GLS", '1980Y1:1996Y1'])
df = pd.DataFrame(data, index=["ACAF", "ACAG", "AOUC"], columns=["endogenous", "lec", "method", "sample"])
equations["ACAF, ACAG, AOUC"] = df
equations["ACAF, ACAG, AOUC"]
[5]:
Workspace: Equations
nb equations: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.eqs
name lec method sample block fstat r2adj dw loglik date
ACAF (ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+ acaf4*(TIME=1995) GLS 1980Y1:1996Y1 0.0000 0.0000 0.0000 0.0000
ACAG ACAG := ACAG[-1]+r VBBP[-1]+(0.006*VBBP[-1]*(TIME=2001)-0.008*(TIME=2008)) GLS 1980Y1:1996Y1 0.0000 0.0000 0.0000 0.0000
AOUC AOUC:=((WCRH/QL)/(WCRH/QL)[1990Y1])*(VAFF/(VM+VAFF))[-1]+PM*(VM/(VAFF+VM))[-1] GLS 1980Y1:1996Y1 0.0000 0.0000 0.0000 0.0000
Lists
[6]:
# using a pandas series
data = ["PWMS; PWXAB; PWXS; QWXAB; QWXS; POIL",
"KL; PROD; QL; RDEBT; RENT; RLBER; SBGX; WCRH; IUGR; SBGXR; WBGR",
"KNFF; PC; PXAB; PMAB; QXAB"]
series = pd.Series(data, index=["ENVI", "IDT", "MAINEQ"])
lists["ENVI, IDT, MAINEQ"] = series
lists["ENVI, IDT, MAINEQ"]
[6]:
Workspace: Lists
nb lists: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.lst
description: Modèle fun
name lists
ENVI PWMS; PWXAB; PWXS; QWXAB; QWXS; POIL
IDT KL; PROD; QL; RDEBT; RENT; RLBER; SBGX; WCRH; IUGR; SBGXR; WBGR
MAINEQ KNFF; PC; PXAB; PMAB; QXAB
Scalars
[7]:
# 1) using a pandas series (only scalar's values)
data = [0.015, -9.e-04, 2.8]
series = pd.Series(data, index=["acaf1", "acaf2", "acaf3"])
scalars["acaf1, acaf2, acaf3"] = series
scalars["acaf1, acaf2, acaf3"]
[7]:
Workspace: Scalars
nb scalars: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.scl
name value relax std
acaf1 0.0150 1.0000 na
acaf2 -0.0009 1.0000 na
acaf3 2.8000 1.0000 na
[8]:
# 2) using a pandas DataFrame (value + relax)
data = [(0.014, 0.98), (-7.e-04, 0.95), (2.3, 0.92)]
df = pd.DataFrame(data, index=["acaf1", "acaf2", "acaf3"], columns=["value", "relax"])
scalars["acaf1, acaf2, acaf3"] = df
scalars["acaf1, acaf2, acaf3"]
[8]:
Workspace: Scalars
nb scalars: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.scl
name value relax std
acaf1 0.0140 0.9800 na
acaf2 -0.0007 0.9500 na
acaf3 2.3000 0.9200 na
Variables
[9]:
# using a pandas DataFrame
data = [[28.89, 31.90, 36.66, 42.13, 9.92],
[np.nan, -39.96, -42.88, -16.33, -41.16],
[1.023, np.nan, 1.046, np.nan, 1.064]]
periods = ["1991Y1", "1992Y1", "1993Y1", "1994Y1", "1995Y1"]
df = pd.DataFrame(data, index=["ACAF", "ACAG", "AOUC"], columns=periods)
df
[9]:
| 1991Y1 | 1992Y1 | 1993Y1 | 1994Y1 | 1995Y1 | |
|---|---|---|---|---|---|
| ACAF | 28.890 | 31.90 | 36.660 | 42.13 | 9.920 |
| ACAG | NaN | -39.96 | -42.880 | -16.33 | -41.160 |
| AOUC | 1.023 | NaN | 1.046 | NaN | 1.064 |
[10]:
variables["ACAF, ACAG, AOUC", "1991Y1:1995Y1"] = df
variables["ACAF, ACAG, AOUC", "1991Y1:1995Y1"]
[10]:
Workspace: Variables
nb variables: 3
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL
name 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1
ACAF 28.89 31.90 36.66 42.13 9.92
ACAG na -39.96 -42.88 -16.33 -41.16
AOUC 1.02 na 1.05 na 1.06
More On IODE Variables Database And pandas
Add one variable:
[11]:
# using a pandas Series
data = list(range(variables.nb_periods))
data[0] = NA
data[-1] = np.nan
values = pd.Series(data, index=variables.periods_as_str)
variables["A4"] = values
variables["A4"]
[11]:
Workspace: Variables
nb variables: 1
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL
name 1960Y1 1961Y1 1962Y1 1963Y1 1964Y1 1965Y1 ... 2009Y1 2010Y1 2011Y1 2012Y1 2013Y1 2014Y1 2015Y1
A4 na 1.00 2.00 3.00 4.00 5.00 ... 49.00 50.00 51.00 52.00 53.00 54.00 na
Update a variable.
Update all values of a variable:
[12]:
# using a pandas Series
values = pd.Series(data, index=variables.periods_as_str)
variables["AOUC"] = values
variables["AOUC"]
[12]:
Workspace: Variables
nb variables: 1
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1960Y1:2015Y1
mode: LEVEL
name 1960Y1 1961Y1 1962Y1 1963Y1 1964Y1 1965Y1 ... 2009Y1 2010Y1 2011Y1 2012Y1 2013Y1 2014Y1 2015Y1
AOUC na 1.00 2.00 3.00 4.00 5.00 ... 49.00 50.00 51.00 52.00 53.00 54.00 na
Set the values for range of (contiguous) periods:
[13]:
# variable[t:t+x] = pandas Series
data = [1.0, NA, 3.0, np.nan, 5.0]
periods = ["1991Y1", "1992Y1", "1993Y1", "1994Y1", "1995Y1"]
variables["AOUC", "1991Y1:1995Y1"] = pd.Series(data, index=periods)
variables["AOUC", "1991Y1:1995Y1"]
[13]:
Workspace: Variables
nb variables: 1
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL
name 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1
AOUC 1.00 na 3.00 na 5.00
Arithmetic Operations On Variables With pandas Series And DataFrames
IODE variables can be used in arithmetic operations with pandas Series and DataFrames.
Let’s first reload the variables database to start from a clean state. Then we will select a subset of variables for the examples below:
[14]:
# reload variables to start from a clean state
variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
# select a subset of variables for the examples below
vars_subset = variables["A*", "1991Y1:1995Y1"]
vars_subset
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.var
394 objects loaded
[14]:
Workspace: Variables
nb variables: 5
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL
name 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1
ACAF 26.24 30.16 34.66 8.16 -13.13
ACAG -30.93 -40.29 -43.16 -16.03 -41.85
AOUC 1.02 1.03 1.03 1.05 1.05
AOUC_ 0.96 0.97 0.98 0.99 1.00
AQC 1.06 1.11 1.15 1.16 1.16
[15]:
data = [2.0, 3.0, 4.0, 5.0, 6.0]
series = pd.Series(data, index=vars_subset.periods_as_str)
series
[15]:
1991Y1 2.0
1992Y1 3.0
1993Y1 4.0
1994Y1 5.0
1995Y1 6.0
dtype: float64
[16]:
# subtract the values of a pandas Series
# from the values of a single variable
updated_ACAF = vars_subset["ACAF"] - series
updated_ACAF
[16]:
Workspace: Variables
nb variables: 1
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL
name 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1
ACAF 24.24 27.16 30.66 3.16 -19.13
[17]:
series = pd.Series(data, index=vars_subset.names)
series
[17]:
ACAF 2.0
ACAG 3.0
AOUC 4.0
AOUC_ 5.0
AQC 6.0
dtype: float64
[18]:
# subtract the values of a pandas Series from the values
# of a subset corresponding to a single period
vars_subset_1995Y1 = vars_subset[:, "1995Y1"] - series
vars_subset_1995Y1
[18]:
Workspace: Variables
nb variables: 5
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1995Y1:1995Y1
mode: LEVEL
name 1995Y1
ACAF -15.13
ACAG -44.85
AOUC -2.95
AOUC_ -4.00
AQC -4.84
[19]:
# define the pandas DataFrame to be used in the example below
data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0],
[6.0, 7.0, 8.0, 9.0, 10.0],
[11.0, 12.0, 13.0, 14.0, 15.0],
[16.0, 17.0, 18.0, 19.0, 20.0],
[21.0, 22.0, 23.0, 24.0, 25.0]])
df = pd.DataFrame(data, index=vars_subset.names, columns=vars_subset.periods_as_str)
df
[19]:
| 1991Y1 | 1992Y1 | 1993Y1 | 1994Y1 | 1995Y1 | |
|---|---|---|---|---|---|
| ACAF | 1.0 | 2.0 | 3.0 | 4.0 | 5.0 |
| ACAG | 6.0 | 7.0 | 8.0 | 9.0 | 10.0 |
| AOUC | 11.0 | 12.0 | 13.0 | 14.0 | 15.0 |
| AOUC_ | 16.0 | 17.0 | 18.0 | 19.0 | 20.0 |
| AQC | 21.0 | 22.0 | 23.0 | 24.0 | 25.0 |
[20]:
# subtract the values of a pandas DataFrame
# from the values of a subset of variables
new_vars_subset = vars_subset - df
new_vars_subset
[20]:
Workspace: Variables
nb variables: 5
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL
name 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1
ACAF 25.24 28.16 31.66 4.16 -18.13
ACAG -36.93 -47.29 -51.16 -25.03 -51.85
AOUC -9.98 -10.97 -11.97 -12.95 -13.95
AOUC_ -15.04 -16.03 -17.02 -18.01 -19.00
AQC -19.94 -20.89 -21.85 -22.84 -23.84
Import/Export IODE workspaces from/to pandas Series and DataFrame
To import / export the content of the comments, identities and lists workspaces from/to a pandas Series object, use the from_series() and to_series() methods.
Alternatively, you can use the series property to export the content of the comments, identities and lists workspaces to a pandas Series object.
[21]:
# ---- to pandas Series ----
# See Comments/Identities/Lists.to_series and
# Comments/Identities/Lists.series
series_cmt = comments.to_series()
print(f"Comments as pandas Series:\n{series_cmt.info()}")
print()
series_idt = identities.to_series()
print(f"Identities as pandas Series:\n{series_idt.info()}")
print()
series_lst = lists.to_series()
print(f"Lists as pandas Series:\n{series_lst.info()}")
# Alternatively
series_cmt = comments.series
series_idt = identities.series
series_lst = lists.series
# ---- from pandas Series ----
# See Comments/Identities/Lists.from_series
comments.from_series(series_cmt)
identities.from_series(series_idt)
lists.from_series(series_lst)
<class 'pandas.core.series.Series'>
Index: 317 entries, ACAF to ZZ_
Series name: Comments
Non-Null Count Dtype
-------------- -----
317 non-null object
dtypes: object(1)
memory usage: 5.0+ KB
Comments as pandas Series:
None
<class 'pandas.core.series.Series'>
Index: 48 entries, AOUC to YSFICR
Series name: Identities
Non-Null Count Dtype
-------------- -----
48 non-null object
dtypes: object(1)
memory usage: 768.0+ bytes
Identities as pandas Series:
None
<class 'pandas.core.series.Series'>
Index: 17 entries, COPY to _SEARCH
Series name: Lists
Non-Null Count Dtype
-------------- -----
17 non-null object
dtypes: object(1)
memory usage: 272.0+ bytes
Lists as pandas Series:
None
To import / export the content of the equations, scalars and variables workspaces from/to a pandas DataFrame object, use the from_frame() and to_frame() methods.
Alternatively, you can use the df property to export the content of the equations, scalars and variables workspaces to a pandas DataFrame object.
[22]:
comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt")
equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs")
identities.load(f"{SAMPLE_DATA_DIR}/fun.idt")
lists.load(f"{SAMPLE_DATA_DIR}/fun.lst")
scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl")
tables.load(f"{SAMPLE_DATA_DIR}/fun.tbl")
variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.cmt
317 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.eqs
274 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.idt
48 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.lst
17 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.scl
161 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.tbl
46 objects loaded
Loading C:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data/fun.var
394 objects loaded
[23]:
# ---- to pandas DataFrame ----
# See Equations/Scalars/Variables.to_frame and
# Equations/Scalars/Variables.df
df_eqs = equations.to_frame()
print(f"Equations as pandas DataFrame:\n{df_eqs.info()}")
print()
df_scl = scalars.to_frame()
print(f"Scalars as pandas DataFrame:\n{df_scl.info()}")
print()
df_vars = variables.to_frame()
print(f"Variables as pandas DataFrame:\n{df_vars.info()}")
# Alternatively
df_eqs = equations.df
df_scl = scalars.df
df_vars = variables.df
# ---- from pandas DataFrame ----
# See Equations/Scalars/Variables.from_frame
equations.from_frame(df_eqs)
scalars.from_frame(df_scl)
variables.from_frame(df_vars)
<class 'pandas.core.frame.DataFrame'>
Index: 274 entries, ACAF to ZZF_
Data columns (total 18 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 lec 274 non-null object
1 method 274 non-null object
2 sample 274 non-null object
3 comment 274 non-null object
4 instruments 274 non-null object
5 block 274 non-null object
6 corr 274 non-null float64
7 stdev 274 non-null float64
8 meany 274 non-null float64
9 ssres 274 non-null float64
10 stderr 274 non-null float64
11 stderrp 274 non-null float64
12 fstat 274 non-null float64
13 r2 274 non-null float64
14 r2adj 274 non-null float64
15 dw 274 non-null float64
16 loglik 274 non-null float64
17 date 274 non-null object
dtypes: float64(11), object(7)
memory usage: 40.7+ KB
Equations as pandas DataFrame:
None
<class 'pandas.core.frame.DataFrame'>
Index: 161 entries, acaf1 to zkf3
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 value 161 non-null float64
1 relax 161 non-null float64
2 std 142 non-null float64
dtypes: float64(3)
memory usage: 5.0+ KB
Scalars as pandas DataFrame:
None
<class 'pandas.core.frame.DataFrame'>
Index: 394 entries, ACAF to ZZF_
Data columns (total 56 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 1960Y1 264 non-null float64
1 1961Y1 280 non-null float64
2 1962Y1 280 non-null float64
3 1963Y1 280 non-null float64
4 1964Y1 281 non-null float64
5 1965Y1 283 non-null float64
6 1966Y1 288 non-null float64
7 1967Y1 288 non-null float64
8 1968Y1 288 non-null float64
9 1969Y1 288 non-null float64
10 1970Y1 359 non-null float64
11 1971Y1 372 non-null float64
12 1972Y1 372 non-null float64
13 1973Y1 373 non-null float64
14 1974Y1 373 non-null float64
15 1975Y1 379 non-null float64
16 1976Y1 379 non-null float64
17 1977Y1 379 non-null float64
18 1978Y1 379 non-null float64
19 1979Y1 379 non-null float64
20 1980Y1 387 non-null float64
21 1981Y1 387 non-null float64
22 1982Y1 387 non-null float64
23 1983Y1 387 non-null float64
24 1984Y1 387 non-null float64
25 1985Y1 388 non-null float64
26 1986Y1 390 non-null float64
27 1987Y1 390 non-null float64
28 1988Y1 390 non-null float64
29 1989Y1 390 non-null float64
30 1990Y1 390 non-null float64
31 1991Y1 390 non-null float64
32 1992Y1 390 non-null float64
33 1993Y1 390 non-null float64
34 1994Y1 392 non-null float64
35 1995Y1 392 non-null float64
36 1996Y1 392 non-null float64
37 1997Y1 392 non-null float64
38 1998Y1 392 non-null float64
39 1999Y1 393 non-null float64
40 2000Y1 393 non-null float64
41 2001Y1 393 non-null float64
42 2002Y1 393 non-null float64
43 2003Y1 393 non-null float64
44 2004Y1 393 non-null float64
45 2005Y1 393 non-null float64
46 2006Y1 393 non-null float64
47 2007Y1 393 non-null float64
48 2008Y1 393 non-null float64
49 2009Y1 393 non-null float64
50 2010Y1 393 non-null float64
51 2011Y1 394 non-null float64
52 2012Y1 394 non-null float64
53 2013Y1 394 non-null float64
54 2014Y1 394 non-null float64
55 2015Y1 394 non-null float64
dtypes: float64(56)
memory usage: 175.5+ KB
Variables as pandas DataFrame:
None
c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\time\sample.py:240: UserWarning: 'sample' is not defined
return self._cython_instance.__str__()
c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\time\sample.py:240: UserWarning: 'sample' is not defined
return self._cython_instance.__str__()
It possible to export a subset of the IODE databases:
[24]:
# export a subset of the IODE Variables database as a pandas DataFrame
vars_subset = variables["A*;*_", "2000Y1:2010Y1"]
vars_subset
[24]:
Workspace: Variables
nb variables: 33
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 2000Y1:2010Y1
mode: LEVEL
name 2000Y1 2001Y1 2002Y1 2003Y1 2004Y1 2005Y1 2006Y1 2007Y1 2008Y1 2009Y1 2010Y1
ACAF 10.05 2.87 -0.93 -6.09 -14.58 -26.54 -28.99 -33.38 -38.41 -37.46 -37.83
ACAG -41.53 18.94 19.98 21.02 22.07 23.11 24.13 25.16 26.19 27.23 28.25
AOUC 1.12 1.14 1.16 1.17 1.17 1.18 1.20 1.22 1.26 1.29 1.31
AOUC_ 1.10 1.14 1.15 1.16 1.15 1.16 1.19 1.20 1.21 1.23 1.25
AQC 1.34 1.38 1.41 1.42 1.40 1.40 1.40 1.41 1.43 1.45 1.46
... ... ... ... ... ... ... ... ... ... ... ...
WCF_ 3716.45 3863.90 3999.57 4147.95 4242.58 4320.97 4463.72 4665.91 4916.65 5042.74 5170.60
WIND_ 1000.14 1035.22 1070.93 1102.91 1115.33 1124.07 1144.27 1178.12 1231.49 1268.86 1301.03
WNF_ 2334.76 2427.49 2512.87 2606.28 2665.82 2715.11 2804.93 2932.23 3089.99 3169.32 3249.75
YDH_ 7276.61 7635.91 7958.39 8331.07 8653.40 8950.54 9299.54 9685.61 10228.84 10630.74 10995.83
ZZF_ 0.69 0.69 0.69 0.69 0.69 0.69 0.69 0.69 0.69 0.69 0.69
[25]:
df = vars_subset.to_frame()
df.shape
[25]:
(33, 11)
[26]:
df
[26]:
| time | 2000Y1 | 2001Y1 | 2002Y1 | 2003Y1 | 2004Y1 | 2005Y1 | 2006Y1 | 2007Y1 | 2008Y1 | 2009Y1 | 2010Y1 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| names | |||||||||||
| ACAF | 10.046611 | 2.867923 | -0.929213 | -6.091565 | -14.582094 | -26.538790 | -28.987288 | -33.378426 | -38.409518 | -37.463510 | -37.827429 |
| ACAG | -41.534787 | 18.939801 | 19.980815 | 21.020502 | 22.066476 | 23.107962 | 24.129637 | 25.160909 | 26.192111 | 27.229955 | 28.253929 |
| AOUC | 1.116238 | 1.140476 | 1.157169 | 1.170490 | 1.167675 | 1.181521 | 1.199462 | 1.219333 | 1.262806 | 1.287132 | 1.307110 |
| AOUC_ | 1.101957 | 1.136244 | 1.150215 | 1.160829 | 1.148021 | 1.164123 | 1.185897 | 1.195166 | 1.213834 | 1.231854 | 1.250164 |
| AQC | 1.338603 | 1.379188 | 1.408816 | 1.419705 | 1.400652 | 1.396973 | 1.398064 | 1.407913 | 1.425645 | 1.446332 | 1.462868 |
| GAP_ | 4.510096 | 3.321449 | 2.647524 | 3.530320 | 5.569508 | 5.716970 | 6.022618 | 6.017820 | 4.944350 | 3.823078 | 3.376524 |
| GOSH_ | 1957.089520 | 2065.833405 | 2150.560958 | 2235.910923 | 2338.703226 | 2435.728167 | 2488.522529 | 2566.343368 | 2666.950277 | 2767.877368 | 2834.234072 |
| PAF_ | 1.197491 | 1.229682 | 1.259968 | 1.286122 | 1.295922 | 1.286290 | 1.283384 | 1.288486 | 1.305041 | 1.326745 | 1.343502 |
| PC_ | 1.234727 | 1.268944 | 1.293650 | 1.312462 | 1.326589 | 1.349003 | 1.371335 | 1.395215 | 1.443821 | 1.471451 | 1.494820 |
| PFI_ | 1.073516 | 1.101770 | 1.121974 | 1.138175 | 1.151583 | 1.171021 | 1.189040 | 1.208363 | 1.248972 | 1.271813 | 1.292278 |
| PROIHP_ | 1.105413 | 1.088832 | 1.072499 | 1.056412 | 1.040566 | 1.024957 | 1.009583 | 0.994439 | 0.979523 | 0.964830 | 0.950357 |
| QAFF_ | 5748.518880 | 5799.949010 | 5873.722479 | 6023.335862 | 6233.004051 | 6369.669081 | 6562.245749 | 6775.703184 | 6888.433029 | 6875.777878 | 6973.598753 |
| QAF_ | 4785.221049 | 4849.609291 | 4924.799385 | 5064.142301 | 5261.273113 | 5391.602139 | 5564.843835 | 5751.420349 | 5847.790032 | 5846.523264 | 5936.558148 |
| QAI_ | 963.297144 | 950.325805 | 948.931158 | 959.209351 | 971.731901 | 978.081737 | 997.377351 | 1024.213763 | 1040.552937 | 1029.172559 | 1036.991863 |
| QAT_ | 7184.569799 | 7271.268016 | 7373.861164 | 7552.955808 | 7792.922441 | 7960.185132 | 8183.601226 | 8428.927049 | 8574.102174 | 8594.675901 | 8726.217012 |
| QBBPPOT_ | 7655.481802 | 7846.625651 | 8008.257249 | 8161.034735 | 8321.948650 | 8515.447900 | 8740.701520 | 8988.561394 | 9237.196352 | 9445.537286 | 9605.212226 |
| QC_ | 4855.413278 | 4970.406979 | 5028.923692 | 5124.198346 | 5256.414928 | 5375.487645 | 5457.675486 | 5582.280773 | 5730.733701 | 5840.309538 | 5889.766110 |
| QQMAB_ | 5180.218215 | 5263.884257 | 5380.635865 | 5550.482666 | 5814.029839 | 6022.171214 | 6314.295655 | 6618.687733 | 6799.968352 | 6785.400829 | 6936.181731 |
| QS_ | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 |
| TFPFHP_ | 0.993773 | 1.003711 | 1.013748 | 1.023886 | 1.034124 | 1.044466 | 1.054910 | 1.065459 | 1.076114 | 1.086875 | 1.097744 |
| VAFF_ | 6883.859391 | 7132.215710 | 7400.688231 | 7746.754153 | 8076.948769 | 8193.069203 | 8421.924597 | 8730.084286 | 8989.594086 | 9122.283229 | 9369.040712 |
| VAF_ | 5730.319882 | 5963.614421 | 6205.064540 | 6513.097789 | 6817.705837 | 6934.982378 | 7141.922643 | 7410.429919 | 7631.630020 | 7756.833308 | 7975.839742 |
| VAI_ | 1153.535695 | 1168.585213 | 1195.623401 | 1233.654821 | 1259.269548 | 1258.102373 | 1279.991145 | 1319.667655 | 1357.967800 | 1365.435020 | 1393.190351 |
| VAT_ | 8880.730664 | 9239.671901 | 9617.675700 | 10073.666293 | 10492.974182 | 10693.831020 | 11025.802341 | 11458.349864 | 11871.102248 | 12141.960623 | 12525.581408 |
| VC_ | 5995.108322 | 6307.170346 | 6505.671010 | 6725.313721 | 6973.104755 | 7251.547841 | 7484.303065 | 7788.480173 | 8274.154525 | 8593.729110 | 8804.137738 |
| VS_ | 16.860422 | 11.864215 | 6.946451 | 9.395299 | 20.993088 | 26.210131 | 21.025449 | 15.223637 | 11.879402 | 6.702546 | 10.939950 |
| WBF_ | 2693.727769 | 2800.592186 | 2898.935640 | 3006.478819 | 3075.041804 | 3131.876447 | 3235.333845 | 3381.873667 | 3563.622541 | 3655.025518 | 3747.687849 |
| WBU_ | 5074.190636 | 5296.606544 | 5504.505284 | 5725.480950 | 5869.288612 | 5991.052046 | 6197.962203 | 6485.787802 | 6850.736280 | 7067.149116 | 7283.594651 |
| WCF_ | 3716.447509 | 3863.897550 | 3999.573377 | 4147.951236 | 4242.577704 | 4320.968444 | 4463.723155 | 4665.913611 | 4916.650999 | 5042.743118 | 5170.600010 |
| WIND_ | 1000.144577 | 1035.218800 | 1070.932873 | 1102.907284 | 1115.334343 | 1124.067720 | 1144.265401 | 1178.120352 | 1231.487898 | 1268.861647 | 1301.025126 |
| WNF_ | 2334.763628 | 2427.492334 | 2512.867505 | 2606.278786 | 2665.816017 | 2715.105256 | 2804.934826 | 2932.231254 | 3089.993676 | 3169.316544 | 3249.751702 |
| YDH_ | 7276.607740 | 7635.905667 | 7958.394498 | 8331.068487 | 8653.402764 | 8950.540446 | 9299.536529 | 9685.613845 | 10228.840906 | 10630.736896 | 10995.831393 |
| ZZF_ | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 |
For the variables workspace, the to_frame() method have additional arguments. For instance, the periods_as_type argument allows to export the periods as a specific type. The periods_as_type argument can be one of the following: str, int or float. The default value is str:
[27]:
df = vars_subset.to_frame(time_axis_name="years", periods_as_type=int)
df
[27]:
| years | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2010 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| names | |||||||||||
| ACAF | 10.046611 | 2.867923 | -0.929213 | -6.091565 | -14.582094 | -26.538790 | -28.987288 | -33.378426 | -38.409518 | -37.463510 | -37.827429 |
| ACAG | -41.534787 | 18.939801 | 19.980815 | 21.020502 | 22.066476 | 23.107962 | 24.129637 | 25.160909 | 26.192111 | 27.229955 | 28.253929 |
| AOUC | 1.116238 | 1.140476 | 1.157169 | 1.170490 | 1.167675 | 1.181521 | 1.199462 | 1.219333 | 1.262806 | 1.287132 | 1.307110 |
| AOUC_ | 1.101957 | 1.136244 | 1.150215 | 1.160829 | 1.148021 | 1.164123 | 1.185897 | 1.195166 | 1.213834 | 1.231854 | 1.250164 |
| AQC | 1.338603 | 1.379188 | 1.408816 | 1.419705 | 1.400652 | 1.396973 | 1.398064 | 1.407913 | 1.425645 | 1.446332 | 1.462868 |
| GAP_ | 4.510096 | 3.321449 | 2.647524 | 3.530320 | 5.569508 | 5.716970 | 6.022618 | 6.017820 | 4.944350 | 3.823078 | 3.376524 |
| GOSH_ | 1957.089520 | 2065.833405 | 2150.560958 | 2235.910923 | 2338.703226 | 2435.728167 | 2488.522529 | 2566.343368 | 2666.950277 | 2767.877368 | 2834.234072 |
| PAF_ | 1.197491 | 1.229682 | 1.259968 | 1.286122 | 1.295922 | 1.286290 | 1.283384 | 1.288486 | 1.305041 | 1.326745 | 1.343502 |
| PC_ | 1.234727 | 1.268944 | 1.293650 | 1.312462 | 1.326589 | 1.349003 | 1.371335 | 1.395215 | 1.443821 | 1.471451 | 1.494820 |
| PFI_ | 1.073516 | 1.101770 | 1.121974 | 1.138175 | 1.151583 | 1.171021 | 1.189040 | 1.208363 | 1.248972 | 1.271813 | 1.292278 |
| PROIHP_ | 1.105413 | 1.088832 | 1.072499 | 1.056412 | 1.040566 | 1.024957 | 1.009583 | 0.994439 | 0.979523 | 0.964830 | 0.950357 |
| QAFF_ | 5748.518880 | 5799.949010 | 5873.722479 | 6023.335862 | 6233.004051 | 6369.669081 | 6562.245749 | 6775.703184 | 6888.433029 | 6875.777878 | 6973.598753 |
| QAF_ | 4785.221049 | 4849.609291 | 4924.799385 | 5064.142301 | 5261.273113 | 5391.602139 | 5564.843835 | 5751.420349 | 5847.790032 | 5846.523264 | 5936.558148 |
| QAI_ | 963.297144 | 950.325805 | 948.931158 | 959.209351 | 971.731901 | 978.081737 | 997.377351 | 1024.213763 | 1040.552937 | 1029.172559 | 1036.991863 |
| QAT_ | 7184.569799 | 7271.268016 | 7373.861164 | 7552.955808 | 7792.922441 | 7960.185132 | 8183.601226 | 8428.927049 | 8574.102174 | 8594.675901 | 8726.217012 |
| QBBPPOT_ | 7655.481802 | 7846.625651 | 8008.257249 | 8161.034735 | 8321.948650 | 8515.447900 | 8740.701520 | 8988.561394 | 9237.196352 | 9445.537286 | 9605.212226 |
| QC_ | 4855.413278 | 4970.406979 | 5028.923692 | 5124.198346 | 5256.414928 | 5375.487645 | 5457.675486 | 5582.280773 | 5730.733701 | 5840.309538 | 5889.766110 |
| QQMAB_ | 5180.218215 | 5263.884257 | 5380.635865 | 5550.482666 | 5814.029839 | 6022.171214 | 6314.295655 | 6618.687733 | 6799.968352 | 6785.400829 | 6936.181731 |
| QS_ | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 | -35.212024 |
| TFPFHP_ | 0.993773 | 1.003711 | 1.013748 | 1.023886 | 1.034124 | 1.044466 | 1.054910 | 1.065459 | 1.076114 | 1.086875 | 1.097744 |
| VAFF_ | 6883.859391 | 7132.215710 | 7400.688231 | 7746.754153 | 8076.948769 | 8193.069203 | 8421.924597 | 8730.084286 | 8989.594086 | 9122.283229 | 9369.040712 |
| VAF_ | 5730.319882 | 5963.614421 | 6205.064540 | 6513.097789 | 6817.705837 | 6934.982378 | 7141.922643 | 7410.429919 | 7631.630020 | 7756.833308 | 7975.839742 |
| VAI_ | 1153.535695 | 1168.585213 | 1195.623401 | 1233.654821 | 1259.269548 | 1258.102373 | 1279.991145 | 1319.667655 | 1357.967800 | 1365.435020 | 1393.190351 |
| VAT_ | 8880.730664 | 9239.671901 | 9617.675700 | 10073.666293 | 10492.974182 | 10693.831020 | 11025.802341 | 11458.349864 | 11871.102248 | 12141.960623 | 12525.581408 |
| VC_ | 5995.108322 | 6307.170346 | 6505.671010 | 6725.313721 | 6973.104755 | 7251.547841 | 7484.303065 | 7788.480173 | 8274.154525 | 8593.729110 | 8804.137738 |
| VS_ | 16.860422 | 11.864215 | 6.946451 | 9.395299 | 20.993088 | 26.210131 | 21.025449 | 15.223637 | 11.879402 | 6.702546 | 10.939950 |
| WBF_ | 2693.727769 | 2800.592186 | 2898.935640 | 3006.478819 | 3075.041804 | 3131.876447 | 3235.333845 | 3381.873667 | 3563.622541 | 3655.025518 | 3747.687849 |
| WBU_ | 5074.190636 | 5296.606544 | 5504.505284 | 5725.480950 | 5869.288612 | 5991.052046 | 6197.962203 | 6485.787802 | 6850.736280 | 7067.149116 | 7283.594651 |
| WCF_ | 3716.447509 | 3863.897550 | 3999.573377 | 4147.951236 | 4242.577704 | 4320.968444 | 4463.723155 | 4665.913611 | 4916.650999 | 5042.743118 | 5170.600010 |
| WIND_ | 1000.144577 | 1035.218800 | 1070.932873 | 1102.907284 | 1115.334343 | 1124.067720 | 1144.265401 | 1178.120352 | 1231.487898 | 1268.861647 | 1301.025126 |
| WNF_ | 2334.763628 | 2427.492334 | 2512.867505 | 2606.278786 | 2665.816017 | 2715.105256 | 2804.934826 | 2932.231254 | 3089.993676 | 3169.316544 | 3249.751702 |
| YDH_ | 7276.607740 | 7635.905667 | 7958.394498 | 8331.068487 | 8653.402764 | 8950.540446 | 9299.536529 | 9685.613845 | 10228.840906 | 10630.736896 | 10995.831393 |
| ZZF_ | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 | 0.688400 |
It is also possible to import a subset of the IODE databases:
[28]:
# existing variables
names = variables.get_names("A*")
# new variables
names += ["AX"]
periods = ["1990Y1", "1991Y1", "1992Y1", "1993Y1", "1994Y1", "1995Y1"]
data = [[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
[6.0, 7.0, 8.0, 9.0, 10.0, 11.0],
[12.0, 13.0, 14.0, 15.0, 16.0, 17.0],
[18.0, 19.0, 20.0, 21.0, 22.0, 23.0],
[24.0, 25.0, 26.0, 27.0, 28.0, 29.0],
[30.0, 31.0, 32.0, 33.0, 34.0, 35.0]]
df = pd.DataFrame(data, index=names, columns=periods)
df
[28]:
| 1990Y1 | 1991Y1 | 1992Y1 | 1993Y1 | 1994Y1 | 1995Y1 | |
|---|---|---|---|---|---|---|
| ACAF | 0.0 | 1.0 | 2.0 | 3.0 | 4.0 | 5.0 |
| ACAG | 6.0 | 7.0 | 8.0 | 9.0 | 10.0 | 11.0 |
| AOUC | 12.0 | 13.0 | 14.0 | 15.0 | 16.0 | 17.0 |
| AOUC_ | 18.0 | 19.0 | 20.0 | 21.0 | 22.0 | 23.0 |
| AQC | 24.0 | 25.0 | 26.0 | 27.0 | 28.0 | 29.0 |
| AX | 30.0 | 31.0 | 32.0 | 33.0 | 34.0 | 35.0 |
[ ]:
# note that the new variable 'AX' has been added with NA values
# for the periods present in the Variables sample but not in the DataFrame
variables.from_frame(df)
variables["A*;B*", "1988Y1:1997Y1"]
Workspace: Variables
nb variables: 10
filename: c:\soft\miniconda3\envs\py312\Lib\site-packages\iode\tests\data\fun.var
description: Modèle fun - Simulation 1
sample: 1988Y1:1997Y1
mode: LEVEL
name 1988Y1 1989Y1 1990Y1 1991Y1 1992Y1 1993Y1 1994Y1 1995Y1 1996Y1 1997Y1
ACAF 25.35 17.17 0.00 1.00 2.00 3.00 4.00 5.00 32.17 39.94
ACAG -37.24 -25.99 6.00 7.00 8.00 9.00 10.00 11.00 -40.24 -32.93
AOUC 0.95 0.98 12.00 13.00 14.00 15.00 16.00 17.00 1.05 1.08
AOUC_ 0.88 0.91 18.00 19.00 20.00 21.00 22.00 23.00 1.00 1.03
AQC 0.93 0.94 24.00 25.00 26.00 27.00 28.00 29.00 1.16 1.20
AX na na 30.00 31.00 32.00 33.00 34.00 35.00 na na
BENEF 281.77 345.16 284.18 197.60 194.04 197.24 231.75 286.67 340.56 348.32
BQY -20.18 -11.33 -34.10 -1.26 -13.75 52.16 66.63 91.09 104.68 113.52
BRUGP 44.67 45.09 0.00 49.77 52.58 51.70 52.06 52.20 52.70 52.85
BVY -18.70 -10.99 -34.10 -1.30 -14.70 58.10 75.90 105.50 123.20 135.62