预测历史数据 [英] Forecasting basis the historical figures
本文介绍了预测历史数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据历史数据预测分配.
I want to forecast the allocations basis the historical figures.
用户提供的手动输入:
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
历史人物的输出:
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
我尝试从总数中计算is_p
的分配,比如说我添加了某些列以计算%of分配:
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.这会给我多少钱来自细分 y,z,k同样如此 - 我将人工输入的9276581 *
%ofx_segment
乘以计算segment_x的值 - 然后,我计算
%_pg
.对于2018年1月的A区,%_pg
= 600 + 200/600 + 200 + 400 + 400 - 然后,我将步骤2中收到的手动输入乘以*从3中收到的%pg在A段的pg中表示'p'
- 然后,最后,我将计算is_p的百分比,我将计算%Y或%N 段%Y中A的pg中pg的p为= 600/600 + 200.
- 从步骤5接收到的值必须与从4接收到的输出相乘.
%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)
推荐答案
您需要将这两个数据帧连接起来才能对两列进行乘法运算.
You need to join those two dataframes to perform multiplication of two columns.
merged_df = segmentallocation.merge(second,on=['year','month'],how='left',suffixes=['','_second'])
for c in interested_columns:
merged_df['allocation'+str(c)] = merged_df['%of allocation'+str(c)] * merged_df[c]
merged_df
year month segment x y z k %of allocationx %of allocationy %of allocationz %of allocationk x_second y_second z_second k_second allocationx allocationy allocationz allocationk
0 2018 FEB A 2094663 2094663 2094663 2094663 1.000000 1.000000 1.000000 1.000000 7,771,691 738,041 217,027 17,363 2.094663e+06 2.094663e+06 2.094663e+06 2.094663e+06
1 2018 JAN A 1600 1600 1600 1600 0.631662 0.631662 0.631662 0.631662 9,267,581 627,129 254,110 14,980 1.010659e+03 1.010659e+03 1.010659e+03 1.010659e+03
2 2018 JAN B 700 700 700 700 0.276352 0.276352 0.276352 0.276352 9,267,581 627,129 254,110 14,980 1.934465e+02 1.934465e+02 1.934465e+02 1.934465e+02
3 2018 JAN C 233 233 233 233 0.091986 0.091986 0.091986 0.091986 9,267,581 627,129 254,110 14,980 2.143269e+01 2.143269e+01 2.143269e+01 2.143269e+01
这篇关于预测历史数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文