Jupie 2020-01-15 11:52 采纳率: 0%
浏览 3804

报错Traceback (most recent call last): File... .format(val=len(data), ind=len(index))) ValueError: Length of passed values is 400, index implies 1

我是个小菜鸟,在尝试写生成高斯分布的作业时被报错:

D:\Anaconda\python.exe "F:/All tasks in BFU/Study abroad/Internship2019.8 in Google/Homework/Course1/Exercise6/exercise6.py"
Traceback (most recent call last):
  File "F:/All tasks in BFU/Study abroad/Internship2019.8 in Google/Homework/Course1/Exercise6/exercise6.py", line 20, in <module>
    y = func(x, mean, std)
  File "F:/All tasks in BFU/Study abroad/Internship2019.8 in Google/Homework/Course1/Exercise6/exercise6.py", line 15, in func
    f = math.exp(-((x - mu) ^ 2)/(2*sigma ^ 2))/(sigma * math.sqrt(2 * math.pi))
  File "D:\Anaconda\lib\site-packages\pandas\core\ops.py", line 1071, in wrapper
    index=left.index, name=res_name, dtype=None)
  File "D:\Anaconda\lib\site-packages\pandas\core\ops.py", line 980, in _construct_result
    out = left._constructor(result, index=index, dtype=dtype)
  File "D:\Anaconda\lib\site-packages\pandas\core\series.py", line 262, in __init__
    .format(val=len(data), ind=len(index)))
ValueError: Length of passed values is 400, index implies 1

Process finished with exit code 1
  我有安装anaconda,但是报错中貌似表明panda这个package的问题。请问大神大佬,我存在什么问题呀应该怎么解决⊙︿⊙,我好像没在网上找到和我一样的问题,不敢和网上的回答一样在命令提示符里输入命令怕搞错(。•́︿•̀。),是我比较菜鸟又急着所以麻烦了!!
 附上我的作业代码:
import math
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.mlab as mlb
data = pd.read_csv('example-exercise6.csv')  # read file of data
# data = data_['time']

mean = data.mean()     # average of data
std = data.std()   # std

def func(x, mu, sigma):
    f = math.exp(-((x - mu) ^ 2)/(2*sigma ^ 2))/(sigma * math.sqrt(2 * math.pi))
    return f

x = np.arange(60, 100, 0.1)
y = func(x, mean, std)
plt.plot(x, y)
plt.hist(data, bins=10, rwidth=0.9, normed=True)

# x = np.arange(145, 155,0.2)
# y = normfun(x, mean, std)
# plt.plot(x,y,'g',linewidth = 3)
# plt.hist(data, bins = 6, color = 'b', alpha=0.5, rwidth = 0.9, normed=True)
# plt.title('stakes distribution')
# plt.xlabel('stakes time')
# plt.ylabel('Probability')

plt.show()

( 其中csv文件是:)

87
88
83
83
86
80
84
90
84
80
94
89
76
  • 写回答

2条回答 默认 最新

  • xjymt 2021-05-07 22:11
    关注

    你的这个问题解决了嘛?

     

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!