Parsing using pd.DataFrame
In [1]:
from mario import Database
import pandas as pd
import numpy as np
IOT Database¶
In [2]:
# Creating indeces according to mario format
regions = ['reg.1']
Z_levels = ['Sector']
sectors = ['sec.1','sec.2']
factors = ['Labor']
satellite = ['CO2']
Y_level = ['Consumption category']
demands = ['Households']
Z_index = pd.MultiIndex.from_product([regions,Z_levels,sectors])
Y_columns = pd.MultiIndex.from_product([regions,Y_level,demands])
In [3]:
# creating matrices
Z = pd.DataFrame(
data = np.array([
[10,70],
[50,10]]),
index = Z_index,
columns= Z_index
)
Y = pd.DataFrame(
data = np.array([
[200],
[80]]),
index = Z_index,
columns= Y_columns,
)
E = pd.DataFrame(
data = np.array([
[30,20]]),
index = satellite,
columns= Z_index,
)
V = pd.DataFrame(
data = np.array([
[220,60]]),
index = factors,
columns= Z_index,
)
EY = pd.DataFrame(
data = np.array([8]),
index = satellite,
columns= Y_columns,
)
In [4]:
Z
Out[4]:
reg.1 | ||||
---|---|---|---|---|
Sector | ||||
sec.1 | sec.2 | |||
reg.1 | Sector | sec.1 | 10 | 70 |
sec.2 | 50 | 10 |
In [5]:
Y
Out[5]:
reg.1 | |||
---|---|---|---|
Consumption category | |||
Households | |||
reg.1 | Sector | sec.1 | 200 |
sec.2 | 80 |
In [6]:
V
Out[6]:
reg.1 | ||
---|---|---|
Sector | ||
sec.1 | sec.2 | |
Labor | 220 | 60 |
In [7]:
E
Out[7]:
reg.1 | ||
---|---|---|
Sector | ||
sec.1 | sec.2 | |
CO2 | 30 | 20 |
In [8]:
EY
Out[8]:
reg.1 | |
---|---|
Consumption category | |
Households | |
CO2 | 8 |
In [9]:
# units as a dict of pd.DataFrames
units= {'Sector':pd.DataFrame('EUR',index=sectors,columns=['unit']),
'Satellite account':pd.DataFrame('Ton',index=satellite,columns=['unit']),
'Factor of production': pd.DataFrame('EUR',index=factors,columns=['unit'])}
In [10]:
# Creating a mario database
data = Database(Z=Z,
Y=Y,
E=E,
V=V,
EY=EY,
table='IOT',
units=units,
name='iot test'
)
In [11]:
print(data)
name = iot test table = IOT scenarios = ['baseline'] Factor of production = 1 Satellite account = 1 Consumption category = 1 Region = 1 Sector = 2
In [12]:
# Calculating matrices needed
data.calc_all(['p'])
Database: to calculate p following matrices are need. ['w'].Trying to calculate dependencies.
In [13]:
# Accessing to matrices
data.p
# or when a specific scenario is needed
data['baseline']['p']
Out[13]:
price index | |||
---|---|---|---|
Region | Level | Item | |
reg.1 | Sector | sec.1 | 1.0 |
sec.2 | 1.0 |
SUT Database¶
In [14]:
# Creating indeces according to mario format
regions = ['reg.1']
activity_level = ['Activity']
commodity_level = ['Commodity']
activities = ['act.1']
commodities = ['com.1']
activity_index = pd.MultiIndex.from_product([regions,activity_level,activities])
commodity_index = pd.MultiIndex.from_product([regions,commodity_level,commodities])
Z_index = activity_index.append(commodity_index)
factors = ['Labor']
satellite = ['CO2']
Y_level = ['Consumption category']
demands = ['Households']
Y_columns = pd.MultiIndex.from_product([regions,Y_level,demands])
In [15]:
# creating matrices
Z = pd.DataFrame(
data = np.array([
[0,70],
[50,0]]),
index = Z_index,
columns= Z_index
)
Y = pd.DataFrame(
data = np.array([
[0],
[20]]),
index = Z_index,
columns= Y_columns,
)
E = pd.DataFrame(
data = np.array([
[30,0]]),
index = satellite,
columns= Z_index,
)
V = pd.DataFrame(
data = np.array([
[20,0]]),
index = factors,
columns= Z_index,
)
EY = pd.DataFrame(
data = np.array([8]),
index = satellite,
columns= Y_columns,
)
In [16]:
Z
Out[16]:
reg.1 | ||||
---|---|---|---|---|
Activity | Commodity | |||
act.1 | com.1 | |||
reg.1 | Activity | act.1 | 0 | 70 |
Commodity | com.1 | 50 | 0 |
In [17]:
Y
Out[17]:
reg.1 | |||
---|---|---|---|
Consumption category | |||
Households | |||
reg.1 | Activity | act.1 | 0 |
Commodity | com.1 | 20 |
In [18]:
V
Out[18]:
reg.1 | ||
---|---|---|
Activity | Commodity | |
act.1 | com.1 | |
Labor | 20 | 0 |
In [19]:
E
Out[19]:
reg.1 | ||
---|---|---|
Activity | Commodity | |
act.1 | com.1 | |
CO2 | 30 | 0 |
In [20]:
EY
Out[20]:
reg.1 | |
---|---|
Consumption category | |
Households | |
CO2 | 8 |
In [21]:
# units as a dict of pd.DataFrames
units= {'Activity':pd.DataFrame('EUR',index=activities,columns=['unit']),
'Commodity':pd.DataFrame('EUR',index=commodities,columns=['unit']),
'Satellite account':pd.DataFrame('Ton',index=satellite,columns=['unit']),
'Factor of production': pd.DataFrame('EUR',index=factors,columns=['unit'])}
In [22]:
# Creating a mario database
data = Database(Z=Z,
Y=Y,
E=E,
V=V,
EY=EY,
table='SUT',
units=units,
name='sut test'
)
In [23]:
print(data)
name = sut test table = SUT scenarios = ['baseline'] Activity = 1 Commodity = 1 Factor of production = 1 Satellite account = 1 Consumption category = 1 Region = 1
In [24]:
#Looking at supply matrix
data.s
Out[24]:
Region | reg.1 | ||
---|---|---|---|
Level | Commodity | ||
Item | com.1 | ||
Region | Level | Item | |
reg.1 | Activity | act.1 | 1.0 |
In [25]:
#Looking at supply matrix
data.u
Out[25]:
Region | reg.1 | ||
---|---|---|---|
Level | Activity | ||
Item | act.1 | ||
Region | Level | Item | |
reg.1 | Commodity | com.1 | 0.714286 |
In [ ]: