Problem:
We have a order with quantity of a product and its unit value. We know that for each product sold we gain 10% but, how should be its quantity if we gain 12% for each product and to have the same total.
PRODUCT | QTY | UNIT.V | GAIN | QTY_X |
---|---|---|---|---|
A | 10 | 300 | 300 | ? |
B | 20 | 200 | 400 | ? |
C | 30 | 100 | 300 | ? |
D | 40 | 400 | 1600 | ? |
In [1]:
from IPython.display import display
import pandas as pd
In [5]:
# data
data = pd.DataFrame([
[10, 300],
[20, 200],
[30, 100],
[40, 400]
], columns=['QTY', 'UNIT.V'],
index=['A', 'B', 'C', 'D'])
display(data)
In [9]:
def gain(unit_v, qty):
return unit_v*qty*0.1
In [17]:
data['GAIN'] = data.apply(lambda v: gain(v['UNIT.V'], v['QTY']), axis=1)
display(data)
In [19]:
def gain_1_2(var_qty, unit_v):
return unit_v*var_qty*0.12
In [14]:
from scipy.optimize import fsolve
In [16]:
help(fsolve)
In [20]:
fsolve(
gain_1_2, [1], args=()
)