I want to forecast the allocations basis the historical figures.
Manual Input provided by the user:
year month x y z k
2018 JAN 9,267,581 627,129 254,110 14,980
2018 FEB 7,771,691 738,041 217,027 17,363
Output from Historical figures:
year month segment pg is_p x y z k
2018 JAN A p Y 600 600 600 600
2018 JAN A p N 200 200 200 200
2018 JAN B r Y 400 400 400 400
2018 JAN A r Y 400 400 400 400
2018 JAN A r N 400 400 400 400
2018 JAN B r N 300 300 300 300
2018 JAN C s Y 200 200 200 200
2018 JAN C s N 10 10 10 10
2018 JAN C t Y 11 11 11 11
2018 JAN C t N 12 12 12 12
2018 FEB A p Y 789 789 789 789
2018 FEB A p N 2093874 2093874 2093874 2093874
I have tried calculating the allocation of is_p
from the total like let say I add certain columns to calculate the %of allocation:
%ofx_segment
= 600+200+400+400/600+200+400+400+400+300+200+10+11+12. This will give me how much x is contributed from segment
The same goes with y,z,k
- I multiply the manual input that is 9276581 *
%ofx_segment
to calculate the value of segment_x
- Then, I calculate
%_pg
. For segment A for Jan 2018, %_pg
= 600+200/600+200+400+400
- Then, I multiply the manual input received from Step 2 * %pg received from 3 for 'p' in pg for A segment
- Then, at last, I will calculate % of is_p, I will calculate % Y or %N
for p in pg for A in segment % Y is =600/600+200.
- The value received from Step 5 has to be multiplied to the output received from 4.
import pandas as pd
first=pd.read_csv('/Users/arork/Downloads/first.csv')
second=pd.read_csv('/Users/arork/Downloads/second.csv')
interested_columns=['x','y','z','k']
second=pd.read_csv('/Users/arork/Downloads/second.csv')
interested_columns=['x','y','z','k']
primeallocation=first.groupby(['year','month','pg','segment'])[['is_p']+interested_columns].apply(f)
segmentallocation=first.groupby(['year','month'])[['segment']+interested_columns].apply(g)
pgallocation=first.groupby(['year','month','segment'])[['pg']+interested_columns].apply(h)
segmentallocation['%of allocation_segment x']
np.array(second)
func = lambda x: x * np.asarray(second['x'])
segmentallocation['%of allocation_segment x'].apply(func)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…