Python output to csv file -


i have question in output csv file in python:

code below:

     import numpy np      import scipy.stats stats      scipy.stats import poisson, norm       # read csv file , obtain corresponding parameter mu, cs , co.       import csv      open('r1.csv', 'r') f:      reader = csv.reader(f)      row in reader:         print row      mu = row[0]      cs = row[1]      co = row[2]       mu = float(mu)      cs = float(cs)      co = float(co)       # generate poisson distribution ,        g = poisson(mu)      p = g.pmf(np.arange(3*mu))       # define z(q) total cost estimation        def z(q):        es = sum(i*p[i] in range(len(p)))        return cs*max((q-es), 0) + co*max((es-q), 0)       # obtain qstar       qstar = np.ceil(poisson.ppf(co/(cs+co), mu))-1      qstar = int(np.float64(qstar).item()) 

this part of code works fine me , got qstar = 5 in simple example. how output csv file?

order_number

5

i have following code call qstar:

    open('test.csv', 'wb') fp:         = csv.writer(fp, delimiter=',')         data = [['order_number'],['qstar']]         a.writerows(data) 

but seems obtain

order_number

qstar

the nhow call 'qstar' correctly?

thank you!

try this:

 open('test.csv', 'wb') fp:             = csv.writer(fp, delimiter=',')             data = [['order_number'],[qstar]]             a.writerows(data) 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -