載入多個時間序列
無論是在個人專案,或是你身為資料科學家的日常工作中,你很可能會遇到需要同時分析與視覺化多個時間序列的情況。
只要每個時間序列的資料分別儲存在檔案中的不同欄位,pandas 函式庫就能讓你輕鬆處理多個時間序列。在接下來的練習中,你會使用一個新的時間序列資料集,內容是美國在 1944 年到 2012 年期間,各類肉品的生產量。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
我們已經以別名 pd 匯入了 pandas。
- 讀取位於
url_meat的 CSV 檔,存成名為meat的 DataFrame。 - 將
meat中的date欄位轉為datetime型別。 - 將
date欄位設為meat的索引。 - 列印
meat中所有數值欄位的摘要統計。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Read in meat DataFrame
meat = ____.____(____)
# Review the first five lines of the meat DataFrame
print(meat.head(5))
# Convert the date column to a datestamp type
meat['date'] = ____(____)
# Set the date column as the index of your DataFrame meat
meat = ____.____(____)
# Print the summary statistics of the DataFrame
print(meat.____)