#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Apr 17 13:06:39 2018 @author: megan """ import pandas as pd accidents = pd.read_csv("NYPD_Motor_Vehicle_Collisions.csv") injury_filter = accidents['NUMBER OF PERSONS INJURED'] > 0 death_filter = accidents['NUMBER OF PERSONS KILLED'] >0 dangerous_accidents = accidents[injury_filter | death_filter] num_dangerous_accidents = len(dangerous_accidents) print("There were",num_dangerous_accidents,"dangerous accidents") num_accidents = len(accidents) print("There were",num_accidents,"accidents total.") prob = num_dangerous_accidents/num_accidents print("The (estimated) probability an accident is dangerous:",prob ) accidents['TIME'] = pd.to_datetime(accidents['TIME']) accidents['TIME'].dt.hour