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

报错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
    关注

    你的这个问题解决了嘛?

     

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置