檢視資料集
在整門課程中,你會分析由 Stanford Open Policing Project 蒐集的羅德島交通攔查資料集。
在開始分析之前,先熟悉資料集非常重要。這個練習中,你會把資料集讀入 pandas,檢視前幾列,然後計算遺漏值的數量。
本練習屬於課程
使用 pandas 分析警方執法活動
練習說明
- 匯入
pandas,並將別名設為pd。 - 將檔案
police.csv讀入為名為ri的 DataFrame。 - 檢視 DataFrame 的前 5 列(稱為「head」)。
- 計算各欄位中的遺漏值數量:使用
.isnull()檢查哪些 DataFrame 元素是遺漏值,接著使用.sum()計算每個欄位中True的數量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the pandas library as pd
import ____ as ____
# Read 'police.csv' into a DataFrame named ri
ri = pd.____(____)
# Examine the head of the DataFrame
print(ri.____)
# Count the number of missing values in each column
print(ri.isnull().____)