I have the following python code which gives two sets of numerical results. I want to use the output for my computation. After each code run I copy the output manually to excel sheet that takes a lot of time. I want to export the numerical values generated by the two print commands to a single excel sheet. My code is
c,mu,fe,lam,r=1,1,20,0.9,0.1
LT=map(lambda x:x/fe,range(0,401))
for fg in LT:
f=fg-(1-r)*fe
if f<=0:
qe=0
else:
if lam<=mu-c*(1-r)/f:
qe=1
elif mu-c*(1-r)/f<lam<=mu/r-c*(1-r)/(r*f):
qe=(mu-lam*r)/(lam*(1-r))-c/(lam*f)
elif mu/r-c*(1-r)/(r*f)<lam:
qe=0
Sqe=c*(lam*qe*(1-r)+lam*r)/(mu-lam*r-qe*lam*(1-r))
S0=c*lam*r/(mu-lam*r)
print("%11.6f %.6f %f %f"% (fg,qe,Sqe,S0))
import numpy as np
p=np.zeros(1002)
import math
for fg in LT:
f=fg-(1-r)*fe
rho=lam/mu
if f<=0:
ne=0
else:
ne=math.floor(mu*f/(c*(1-r)))
if rho!=1:
p[0]=(1-rho)*(1-r*rho)/(1-r*rho*(1-r)*rho**(ne+1))
else:
p[0]=1/(ne+1)
for n in range(1,1001):
if n<ne:
p[n]=p[0]*rho**n
else:
p[n]=p[0]*rho**n*r**(n-ne)
Sne=sum(p[n]*lam*c*(n+1)/mu for n in range(0,ne))+sum(p[n]*lam*r*c*(n+1)/mu for n in range(ne,1001))
Sn0=sum(p[n]*lam*r*c*(n+1)/mu for n in range(0,1001))
print("%11.6f %.6f %f %f"%(fg,ne,Sne,Sn0))
Numpy as a module to export in .csv that is a format readable by Excel.
I personally googled it last year and it turned out someone just answered that in here: https://stackoverflow.com/questions/6081008/dump-a-numpy-array-into-a-csv-file
Also you'll need to convert into a numpy array.