2017-09-24 95 views
0

當我嘗試散點圖時,我在'時間'上得到一個關鍵錯誤,我如何分散繪製這些列?當我試圖散點圖時,如何分散繪圖時間,我在'時間'上得到了keyerror?

high  time 
0 17.23 10:37:00 
1 17.64 14:01:00 
2 15.28 09:31:00 
3 15.56 11:41:00 
4 15.56 11:42:00 
5 15.25 09:30:00 
6 15.25 09:49:00 
7 15.10 15:52:00 
8 16.41 10:40:00 
9 17.75 15:09:00 
10 17.75 15:10:00 
11 19.20 09:41:00 

df_high.plot.scatter(x='time', y='high', c=None, s=None) 
plt.show() 
+0

我懷疑D型細胞沒有被自動設置。用'df ['time'] .dtype'檢查。你可能想要'datetime' dtype。可以用'pd.to_datetime'之類的東西進行轉換,或者用適當的dtype加載數據。 – rmharrison

回答

2
df.set_index('time').sort_index().plot(style='.') 

enter image description here

+0

Thankyou ...有用。只是所以我明白了一點,我的'時間'專欄可能不是日期時間格式?或者,我應該把我的'時間'欄作爲索引嗎? –

+0

@RossDemtschyna是的,至少使用索引是最安全的方法。 – Wen