不明白:ValueError:只能用多索引对索引进行元组

2024-10-02 04:24:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这个问题已经存在了,但答案对我没有帮助。

def function(T,theta,A):
   x=(T-theta)/A
   return(x)

filen=pd.read_csv('filename')
filelist=[file,file2,...,filen)
labels=['name1','name2',...]
colors=['red','blue','green',...]
for i in range(len(filelist)):
    x=filelist[i]['column1']
    y=filelist[i]['column2']
    y2=(1/y)
    plt.plot(x, y2, colors[i], label=labels[i])
    plt.legend()
    plt.plot()
    w=np.where(x>170)
    print(x[w])  #error, can only tuple index with multiindex
    other_fit=curve_fit(function,x,y)
    popt, pcov=other_fit
    plt.plot(x, function(x, *popt), colors2[i], label=labels2[i])
    plt.show()

错误发生在x[w]
当我不在for循环中时,没有错误。

The error message is as follows:

ValueError: Can only tuple-index with a MultiIndex

Tags: onlyforlabelsplotfunctionplterrorlabel
1条回答
网友
1楼 · 发布于 2024-10-02 04:24:41

尝试更改:

w=np.where(x>170)

致:

w = x[x>170]

np.where在您的情况下返回一个元组:

Returns

If only `condition` is given, return the tuple
``condition.nonzero()``, the indices where `condition` is True.

相关问题 更多 >

    热门问题