開始使用免費開始

建立 DateTimeIndex

擁有 DatetimeIndex 有多種好處。首先,你可以用中括號語法選擇任意時間區間,或只用一行程式碼就能畫出折線圖。

請在 apple 股票資料集上練習這些操作。此資料集已將 Date 載入為 datetime 欄位。

本練習屬於課程

Python 中的異常偵測

檢視課程

練習說明

  • 將 Date 欄設為 apple DataFrame 的索引。
  • 建立一張紅色折線圖,內容為 Apple 股票的 Open 欄位,時間從 2008 年 7 月初到 2013 年 12 月 9 日。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Set the Date column as a DatetimeIndex
apple.____(____)

# Plot the opening prices for the instructed range
apple____

plt.title("Opening prices of Apple stocks from the beginning of July of 2008 to December of 2013.")
plt.show()
編輯並執行程式碼