<jupyter_start><jupyter_text>Fetching the data from the cloud.<jupyter_code>url="https://raw.githubusercontent.com/BuzzFeedNews/nics-firearm-background-checks/master/data/nics-firearm-background-checks.csv"
df=pd.read_csv(url)
# df = pd.read_csv("nics-firearm-background-checks.csv")
df.head(5)
df.info()
df.shape
df.describe()<jupyter_output><empty_output><jupyter_text>Checking for duplicates<jupyter_code>df_duplicates = df.drop_duplicates()
df_duplicates.shape<jupyter_output><empty_output><jupyter_text>Number of missing value per column<jupyter_code>null_columns=df.columns[df.isnull().any()]
df[null_columns].isnull().sum()
# print(df[df.isnull().any(axis=1)][null_columns].head())<jupyter_output><empty_output><jupyter_text>Filling missing valuesAfter going through the columns and it's type, I concluded to fill the missing values with 0. Reason to this is because the information only tells us how many background check were performed for each permit type, and if the value is NaN then it must mean that there weren't any or unavailable.<jupyter_code>df.fillna(0,inplace=True)
df.info()
df.describe()<jupyter_output><empty_output><jupyter_text>Parsing column 'month' into month, year<jupyter_code>df['str_split'] = df.month.str.split('-')
df['year'] = df.str_split.str.get(0)
df['months'] = df.str_split.str.get(1)

print(df.head(5))<jupyter_output><empty_output><jupyter_text>EDA<jupyter_code>eda = df
eda.head()
# ax=df.plot(x="state", y="permit_recheck", kind="bar")
# df.plot(x="state",y="handgun", kind="bar", ax=ax, color="blue")
# df.plot(x="state", y="long_gun", kind="bar", ax=ax, color="red")
# plt.show()
x =eda["state"].unique()
x
eda.loc[eda["state"]=='Alabama'].handgun.sum()

data = []
for state in eda["state"].unique():
    data.append(eda.loc[eda["state"]==state].totals.sum())
print(list(data))
_ = plt.scatter(x=x,y=data,color="blue")
_ = plt.xlabel('states')
_ = plt.ylabel('handgun')
plt.xticks(rotation=90)
plt.show()
fig=plt.figure(figsize=(18, 5), dpi= 80, facecolor='w', edgecolor='k')
# df['year'] = pd.to_datetime(df['year'])
_ = plt.scatter(x=x,y=data)
_ = plt.xlabel('states')
_ = plt.ylabel('# of checks')
plt.xticks(rotation=90)
# plt.show()
plt.savefig()
fig=plt.figure(figsize=(18, 5), dpi= 80, facecolor='w', edgecolor='k')
df['year'] = pd.to_datetime(df['year'])
ds= df[df['year'].dt.year == 2014]
ds.groupby(['state'])["totals"].apply(lambda x : x.astype(int).sum()).plot( kind="bar")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1926046322633076, 'fraction_numerical': 0.010158472165786265, 'mean_word_length': 7.792857142857143, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '322467', 'license': 'MIT', 'n_tokens_mistral': 972, 'n_tokens_neox': 946, 'n_words': 153, 'path': 'notebook/nic-firearm-background-check-ETL.ipynb', 'repo_name': 'Cng000/Gun-violence-analysis', 'size': '2461'}