首页 > 解决方案 > 使用 stats norm 的带有钟形曲线图的 pandas 标准差

问题描述

我的数据框是

在此处输入图像描述 在这里,我想要上述数据帧的标准偏差,并且需要一个标准偏差图。

我用下面的代码

import numpy as np   
import scipy.stats as stats
import pylab as pl 
import pandas as pd


h=pd.read_excel(r"C:\Users\monthlyReports\standard_deviation\stan_rawdata.xlsx")

fit = stats.norm.pdf(h, np.mean(h), np.std(h))  
pl.plot(h,fit,'-o')
pl.hist(h,normed=True)     
pl.show()

但我收到类型错误:

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-830c3a5f6c7c> in <module>()
      7 
      8 
----> 9 fit = stats.norm.pdf(h, np.mean(h), np.std(h))  #this is a fitting indeed
     10 
     11 pl.plot(h,fit,'-o')

      ~\AppData\Local\Continuum\anaconda3\lib\sitepackages\scipy\stats\_distn_infrastructure.py in pdf(self, x, *args, **kwds)

  1650         args = tuple(map(asarray, args))

   1651         dtyp = np.find_common_type([x.dtype, np.float64], [])

-> 1652         x = np.asarray((x - loc)/scale, dtype=dtyp)

   1653         cond0 = self._argcheck(*args) & (scale > 0)

   1654         cond1 = self._support_mask(x) & (scale > 0)


TypeError: unsupported operand type(s) for -: 'str' and 'float'

标签: pythonpandasnumpy

解决方案


推荐阅读