不明白:值错误:只能使用多索引元组索引



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

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 循环中时,没有错误。

错误消息如下:

ValueError: Can only tuple-index with a MultiIndex

尝试更改:

w=np.where(x>170)

自:

w = x[x>170]

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

返回

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

最新更新