代码正在运行,但是有一个'DeprecationWarning'-scipy.stats

Lab*_*bah 0 python csv statistics numpy scipy

我写了这段代码来计算大样本的模式和标准偏差:

import numpy as np
import csv
import scipy.stats as sp
import math

r=open('stats.txt', 'w') #file with results
r.write('Data File'+'\t'+ 'Mode'+'\t'+'Std Dev'+'\n')
f=open('data.ls', 'rb') #file with the data files

for line in f:
    dataf=line.strip()
    data=csv.reader(open(dataf, 'rb'))
    data.next()
    data_list=[]
    datacol=[]
    data_list.extend(data)
    for rows in data_list:
            datacol.append(math.log10(float(rows[73])))
    m=sp.mode(datacol)
    s=sp.std(datacol)
    r.write(dataf+'\t'+str(m)+'\t'+str(s)+'\n')
    del(datacol)
    del(data_list)
Run Code Online (Sandbox Code Playgroud)

哪个效果很好 - 我想!但是,在我运行代码后,我的终端上出现了一条错误消息,我想知道是否有人可以告诉我这意味着什么?

 /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1328: DeprecationWarning:     scipy.stats.std is deprecated; please update your code to use numpy.std.
    Please note that:
    - numpy.std axis argument defaults to None, not 0
    - numpy.std has a ddof argument to replace bias in a more general manner.
      scipy.stats.std(a, bias=True) can be replaced by numpy.std(x,
      axis=0, ddof=0), scipy.stats.std(a, bias=False) by numpy.std(x, axis=0,
      ddof=1).
  ddof=1).""", DeprecationWarning)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1304: DeprecationWarning: scipy.stats.var is deprecated; please update your code to use numpy.var.
Please note that:
    - numpy.var axis argument defaults to None, not 0
    - numpy.var has a ddof argument to replace bias in a more general manner.
      scipy.stats.var(a, bias=True) can be replaced by numpy.var(x,
      axis=0, ddof=0), scipy.stats.var(a, bias=False) by var(x, axis=0,
      ddof=1).
  ddof=1).""", DeprecationWarning)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420: DeprecationWarning: scipy.stats.mean is deprecated; please update your code to use numpy.mean.
Please note that:
    - numpy.mean axis argument defaults to None, not 0
    - numpy.mean has a ddof argument to replace bias in a more general manner.
      scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
axis=0, ddof=1).
  axis=0, ddof=1).""", DeprecationWarning)
Run Code Online (Sandbox Code Playgroud)

Mat*_*att 5

这些是弃用警告,通常意味着您的代码将起作用,但可能会在将来的版本中停止工作.

目前你有这条线s=sp.std(datacol).看起来警告建议使用numpy.std()而不是进行scipy.stats.std()此更改可能会使此警告消失.

如果您不关心弃用警告并希望按原样使用代码,则可以使用警告模块对其进行抑制.例如,如果您有一个fxn()生成DeprecationWarning 的函数,您可以像这样包装它:

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()  #this function generates DeprecationWarnings
Run Code Online (Sandbox Code Playgroud)