<jupyter_start><jupyter_text>NYC traffic accidents over a 4 year period  Filter and SubsetDownload this dataset stored on dropbox.<jupyter_code>## import necessary libraries

import pandas as pd
## read the dataset into notebook

df = pd.read_csv("hw08-data/accidents-nyc.csv")
df.head()
## see the overall info about this dataset

df.info()
## create a series of crash dates.

df["CRASH DATE"]
## Which borough had the most crashes?

df["BOROUGH"].value_counts()
## which type of vehicle was primary vehicle involved in crashes?
## SHOW ONLY THE TOP 7
df["VEHICLE TYPE CODE 1"].value_counts().head(7)
## What were a FIVE unusual primary vehicles to get into a crash?
df["VEHICLE TYPE CODE 1"].value_counts().tail(5)

## create a subset of data for only Queens
## place it in a dataframe called df_q

df_q = df[df["BOROUGH"] == "QUEENS"]
df_q
## CHALLENGE (as in you have to google this)
## How many people were killed in Queens in accidents?

df_q["NUMBER OF PERSONS KILLED"].sum()
df_q["NUMBER OF PERSONS KILLED"].value_counts()
## Same
## how many cyclists were killed in Queens?

df_q["NUMBER OF CYCLIST KILLED"].sum()
## Filter and subset 
## create a dataset for Manhattan that involved taxi cabs as the primary vehicle cause

fil_taxi = df["VEHICLE TYPE CODE 1"] == "Taxi"
fil_manhattan = df["BOROUGH"] == "MANHATTAN"

df[fil_manhattan & fil_taxi]
## What were the top 8 causes of accidents across all the boroughs?
## by primary vehicle cause

df["CONTRIBUTING FACTOR VEHICLE 1"].value_counts().head()


## What were the top 8 causes of accidents across all the boroughs?
## by secondary vehicle cause
df["CONTRIBUTING FACTOR VEHICLE 2"].value_counts().head()

## What were the 5 fewest causes for primary vehicles causing the accident

df["CONTRIBUTING FACTOR VEHICLE 1"].value_counts().tail()
## list ALL the causes as unique values (in other words, create a list of the causes)

df["CONTRIBUTING FACTOR VEHICLE 1"].unique()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10437881873727088, 'fraction_numerical': 0.008146639511201629, 'mean_word_length': 5.121495327102804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '241351', 'license': 'MIT', 'n_tokens_mistral': 660, 'n_tokens_neox': 613, 'n_words': 249, 'path': 'homework/hw-for-wk-09-filter-subset-SOLUTION.ipynb', 'repo_name': 'sandeepmj/22spring-advanced-data', 'size': '1964'}