python - 使用 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'
解决方案
推荐阅读
- python - 将 Gerrit 触发器与附加阶段相结合
- autodesk-forge - forge properties.sqlite vs viewable json for revit 类型参数
- html - css - 根据父母数量的奇偶性选择每个元素(CSS或Less但没有JS)
- python - Discord 机器人无法连接
- c++ - C++中向量类的重载运算符+从+=开始
- java - 如何使用 ObjectMapper 将字符串转换为 JSON?
- reactjs - 反应打字稿。使用对象填充数组状态的问题
- sql - SAS - 创建增量表
- couchbase - Couchbase N1QL:GROUP BY CASE 子句不起作用
- reactjs - React/Redux 重复组件无法访问操作