<jupyter_start><jupyter_text>TOP 10 Primary Crash Causes<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
import bqplot
import ipywidgets
import seaborn as sn
crash = pd.read_csv('Traffic_Crashes_Crashes.csv')
crash["CRASH_DATE"] = pd.to_datetime(crash["CRASH_DATE"])
crash_sub = crash[crash["CRASH_DATE"] >=pd.to_datetime('20200101')]
crash_sub = crash_sub[crash_sub["CRASH_DATE"] <=pd.to_datetime('20210101')]
crash_sub["Count"] = 1
crash_sub
crash_sub2=pd.DataFrame()
crash_sub2["PRIM_CONTRIBUTORY_CAUSE"]=crash_sub["PRIM_CONTRIBUTORY_CAUSE"]
crash_sub2["Count"]=crash_sub["Count"]
crash_sub2
cause = crash_sub2.groupby("PRIM_CONTRIBUTORY_CAUSE").sum().reset_index()
cause = cause.sort_values(by='Count',ascending=False)
cause_10=cause.reset_index()
cause_10=cause_10[:10]
cause_10
cause_10["PRIM_CONTRIBUTORY_CAUSE"].to_list()
# Bar graph of the top 15 PRIMARY_CONTRIBUTORY

plt.figure(figsize=(15,15))

y= cause_10["Count"].to_list()
x= cause_10["PRIM_CONTRIBUTORY_CAUSE"].to_list()

sn.barplot(y, x)
plt.title('Top 10 Traffic Crashes Primary Contributory Cause', size=30)
plt.ylabel("Primary Contributory Cause", size=25,rotation=90)
plt.xlabel("Number of Crashes", size=25)
plt.yticks(size=20)
plt.xticks(size=20)<jupyter_output>/opt/anaconda3/envs/DataViz/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning
{'fraction_non_alphanumeric': 0.12332112332112333, 'fraction_numerical': 0.04151404151404151, 'mean_word_length': 8.529069767441861, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '388392', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 658, 'n_tokens_neox': 598, 'n_words': 122, 'path': 'TOP 10 Primary Crash Causes.ipynb', 'repo_name': 'yujingl2/yujingl2.github.io', 'size': '1638'}