检查数据集
在整个课程中,您将分析一份由 Stanford Open Policing Project 收集的罗德岛交通拦截数据集。
在开始分析之前,先熟悉数据集非常重要。本练习中,您将把数据集读入 pandas,查看前几行数据,然后统计缺失值的数量。
本练习是课程的一部分
使用 pandas 分析警务活动
练习说明
- 使用别名
pd导入pandas。 - 将文件
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().____)