这三个函数为我提供了从0状态到接下来365个状态(或天数)的客户数量和订单的进度。在function state_evolution
中,我想绘制第行的输出
custA = float(custA*1.09**(1.0/365))
与第行的输出相对应
^{pr2}$对custB
执行相同的操作,这样我就可以以图形方式比较它们的输出。在
def get_state0():
""" functions gets four columns from base data and finds their state 0"""
statetype0 = {'custt':{'typeA':100,'typeB':200}}
orderstype0 = {'orders':{'typeA':1095, 'typeB':4380}}
return {'custtypeA' : int(statetype0['custt']['typeA']),
'custtypeB' : int(statetype0['custt']['typeB']),
'ordstypeA': orderstype0['orders']['typeA'],'A':1095, 'B':4380,
'ordstypeB':orderstype0['orders']['typeB'],
'day':0 }
def state_evolution(state):
"""function takes state 0 and predicts state evolution """
custA = state['custtypeA']
custB = state['custtypeB']
ordsA = state['ordstypeA']
ordsB = state['ordstypeB']
A = state['A']
B = state['B']
day = state['day']
# evolve day
day += 1
#evolve cust typea
custA = float(custA*1.09**(1.0/365))
#evolve cust typeb
custB = float (custB*1.063**(1.0/365))
# evolve orders cust type A
ordsA += int(custA * order_rateA(day))
A = sum(80 + random.random() * 50 for i in range(ordsA))
# evolve orders cust type B
ordsB += int(custB * order_rateB(day))
B = sum(70 + random.random() * 40 for i in range(ordsB))
return {'custtypeA':custA ,'ordstypeA':ordsA, 'A':A, 'B':B,
'custtypeB':custB, 'ordstypeB':ordsB, 'day': day}
def show_all_states():
""" function runs state evolution function to find other states"""
s = get_state0()
for day in range(365):
s = state_evolution(s)
print day, s
您应该执行以下操作:
custA
函数,使它返回一个序列(list,tuple),比如365个条目。或者,在列表理解或for循环中使用custA
来获得365个结果的序列ordsA
函数执行相同的操作,以获得另一个序列。在从现在开始,你可以根据自己的需要做不同的事情。在
如果您希望两个图并行(叠加),则:
如果要关联数据,可以绘制散点图(更快),或使用点标记进行常规绘图(速度较慢但更可自定义IMO):
^{pr2}$最后,如果数据是不规则采样的,您还可以提供横轴值的序列。例如,这样可以只绘制工作日的结果,而不会“崩溃”周末(否则,星期五和星期一之间的差距看起来就像一天):
希望这有帮助!在
编辑:关于excel,如果我理解正确,你已经有一个csv文件。然后,您可以使用
csv
python模块,或者自己这样阅读:现在,如果您有一个实际的
.xls
或.xlsx
文件,请使用可以下载here或通过在命令提示符下运行pip install xlrd
的模块。在相关问题 更多 >
编程相关推荐