In [1]:
import pandas as pd
import os
import pkg_resources
from openfisca_senegal import SenegalTaxBenefitSystem
asset_directory = os.path.join(
pkg_resources.get_distribution('openfisca-senegal').location,
'openfisca_senegal',
'assets',
)
tax_benefit_system = SenegalTaxBenefitSystem()
In [2]:
scenario = tax_benefit_system.new_scenario()
min_salaire = 600e3
max_salaire = 50e6
step = 5000
count = int((max_salaire - min_salaire) / step + 1)
year = 2015
scenario.init_single_entity(
parent1={},
period=year,
axes=[
{
'count': count,
'min': min_salaire,
'max': max_salaire,
'name': 'salaire',
},
{
'count': 9,
'min': 1,
'max': 5,
'name': 'nombre_de_parts',
},
],
)
simulation = scenario.new_simulation()
In [3]:
salaire = simulation.calculate('salaire', period = year)
nombre_de_parts = simulation.calculate('nombre_de_parts', period = year)
impot_revenus = simulation.calculate('impot_revenus', period = year)
print salaire[:10]
In [4]:
result = pd.DataFrame({
'salaire': salaire,
'nombre_de_parts': nombre_de_parts,
'impots_revenus': impot_revenus,
})
In [5]:
result_reshaped = result.set_index(['nombre_de_parts', 'salaire']).unstack('nombre_de_parts')
result_reshaped
Out[5]:
In [7]:
data_path = os.path.join(
asset_directory,
'bareme_2012_valide_le_10_01_2013.xls'
)
test = pd.read_excel(data_path, skiprows = 2, index_col = 1)
test = test.drop(['Unnamed: 0', 'TRIMF/Pers'], axis = 1)
test = test[[u'1 part', u'1,5 parts', u'2 parts', u'2,5 parts', u'3 parts',
u'3,5 parts', u'4 parts', u'4,5 parts', u'5 parts']]
In [8]:
result_reshaped.columns
Out[8]:
In [9]:
test.columns = result_reshaped.columns
test.index = result_reshaped.index
In [10]:
print test.head()
print result_reshaped.head()
In [11]:
errors = (test - result_reshaped)
In [12]:
print errors.abs().max()
In [13]:
print (errors.abs() > 0).sum()
In [14]:
erroneous_nombre_de_parts = 0
indices = (errors.abs() > 0).any()[(errors.abs() > 0).any()].index.tolist()
In [15]:
for index in indices:
print errors.loc[errors[index] > 0, index]
In [16]:
result_reshaped.to_excel(os.path.join(asset_directory, 'result.xls'))
In [17]:
errors.to_excel(os.path.join(asset_directory, 'errors.xls'))
In [19]:
scenario = tax_benefit_system.new_scenario()
min_salaire = 600e3
max_salaire = 100e6
step = 1000
count = int((max_salaire - min_salaire) / step + 1)
scenario.init_single_entity(
parent1={},
period='2015',
axes=[
{
'count': count,
'min': min_salaire,
'max': max_salaire,
'name': 'salaire',
},
{
'count': 9,
'min': 1,
'max': 5,
'name': 'nombre_de_parts',
},
],
)
simulation = scenario.new_simulation()
salaire = simulation.calculate('salaire', period = year)
nombre_de_parts = simulation.calculate('nombre_de_parts', period = year)
impot_revenus = simulation.calculate('impot_revenus', period = year)
result = pd.DataFrame({
'salaire': salaire,
'nombre_de_parts': nombre_de_parts,
'impots_revenus': impot_revenus,
})
result.salaire = result.salaire.astype(int)
result_reshaped_step_1000 = result.set_index(['nombre_de_parts', 'salaire']).unstack('nombre_de_parts')
result_reshaped_step_1000
Out[19]:
In [20]:
result_reshaped_step_1000.to_excel(os.path.join(asset_directory, 'result_step_1000CFA.xlsx'))
In [ ]: