載入你的時間序列資料
在 Python 中,最常見的作法是使用 pandas 函式庫來匯入時間序列資料。你可以用 pandas 的 read_csv() 將檔案內容讀入成為一個 DataFrame。指令如下:
df = pd.read_csv("name_of_your_file.csv")
當資料載入到 Python 後,你可以呼叫 .head(n=5) 方法來顯示 DataFrame 的前幾列,其中 n=5 表示要印出前 5 列。
在這個練習中,你會讀入一個時間序列資料集,內容是 1860 到 1959 年間「great」發明與科學發現的數量,並顯示其前 5 列。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
- 以別名
pd匯入pandas函式庫。 - 將位於
url_discoveries的 csv 檔案讀入為名為discoveries的 DataFrame。 - 使用
.head()方法列印出該 DataFrame 的前 5 列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import pandas
____
# Read in the file content in a DataFrame called discoveries
discoveries = ____(url_discoveries)
# Display the first five lines of the DataFrame
print(discoveries.____)