簡體   English   中英

Python TypeError: unhashable type: 'slice'

[英]Python TypeError: unhashable type: 'slice'

我收到了錯誤:

TypeError: unhashable type: 'slice' 

運行以下代碼后:

train=data[:training_data_len]
valid=data[training_data_len:]
valid['Predictions']=predictions
plt.figure(figsize=(20,10))
plt.title('Model')
plt.xlabel('Date', fontsize=20)
plt.ylabel('Close Price USD',fontsize=20)
plt.plot(train['Close'])
plt.plot(valid[['Close','Predictions']])
plt.legend(['Train', 'Val', 'Predictions'], loc='lower right')
plt.show

在''training_data_len''寫成之前:

data_close=df.filter(['Close'])
dataset=data_close.values 
training_data_len = math.ceil(len(dataset) * 0.8) 
training_data_len

等於 202。

data不是一個列表,而是一個 dataframe (與df相同的類型)。 你需要改變

train = data[:training_data_len]

train = data['Close'][:training_data_len]

和相同的valid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM