探索 Jobs 資料集
在這個練習中,你會探索新的 jobs DataFrame,裡面包含 2000–2010 年間美國各產業的失業率。你會看到,這個資料集包含 16 個產業的時間序列,以及 122 個時間點(10 年中每個月各 1 筆)。一般來說,資料科學專案的典型流程會包含資料清理與探索,所以我們先從讀取資料並檢查是否有遺漏值開始。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
我們已經將 pandas 以 pd 匯入。
- 讀取位於
url_jobs的 CSV 檔為名為jobs的 DataFrame,並檢視各欄位的資料型別。 - 將
jobs中的datestamp欄位轉換為datetime型別。 - 將
datestamp欄位設為jobs的索引。 - 列印
jobs各欄位的遺漏值數量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Read in jobs file
jobs = ____
# Print first five lines of your DataFrame
print(jobs.head(5))
# Check the type of each column in your DataFrame
print(jobs.dtypes)
# Convert datestamp column to a datetime object
jobs[____] = ____(jobs[____])
# Set the datestamp columns as the index of your DataFrame
jobs = ____('datestamp')
# Check the number of missing values in each column
print(jobs.isnull().____())