Skip to content

Analyzing Police Activity with pandas

Run the hidden code cell below to import the data used in this course.

import pandas as pd
ri = pd.read_csv('datasets/police.csv')
ri.head()
ri.shape
print(ri.isnull().sum())
ri.drop(['state', 'county_name'], axis=1, inplace=True)
print(ri.shape)
# Count the number of missing values in each column
print(ri.isnull().sum())
# Drop all rows that are missing 'driver_gender'
ri.dropna(subset=['driver_gender'], inplace=True)
# Count the number of missing values in each column (again)
print(ri.isnull().sum())
# Examine the shape of the DataFrame
print(ri.shape)
ri.dtypes
# Examine the head of the 'is_arrested' column
print(ri.is_arrested.head())
# Change the data type of 'is_arrested' to 'bool'
ri['is_arrested'] = ri.is_arrested.astype('bool')