<jupyter_start><jupyter_text>Import Libraries<jupyter_code># for data analysis
import pandas as pd
import numpy as np

# for data visualization
import plotly.express as px

# to download files
from google.colab import files<jupyter_output><empty_output><jupyter_text>Import data<jupyter_code># import csv file for data analysis
df_hc = pd.read_csv("https://raw.githubusercontent.com/ireneliu0106/hate_crime_analysis/main/Victims_Incidents.csv")
# preview data
df_hc.head()<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code># rename the columns
df_hc = df_hc.rename(columns = {"Race/Ethnicity/Ancestry:":"Race",
                                "Victims1":"Victims",
                                "Known\noffenders2":"Known Offenders"})
# preview dataframe
df_hc.head()
# preview dataframe info
df_hc.info()
# turn column headers into a list
hc_list = df_hc.columns.tolist()
# remove "Year" from the list because it's not a string
hc_list.remove("Year")
# loop through the columns to remove comma
for col in hc_list:
  df_hc[col] = df_hc[col].str.replace(",","")
# remove "Race" from the list because we will keep it as object
hc_list.remove("Race")
# loop through the columns to convert data to int
for col in hc_list:
  df_hc[col] = df_hc[col].astype(int)

# preview dataframe
df_hc.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 45 entries, 0 to 44
Data columns (total 6 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   Race             45 non-null     object
 1   Incidents        45 non-null     int64 
 2   Offenses         45 non-null     int64 
 3   Victims          45 non-null     int64 
 4   Known Offenders  45 non-null     int64 
 5   Year             45 non-null     int64 
dtypes: int64(5), object(1)
memory usage: 2.2+ KB<jupyter_text>Data Analysis / Visualization<jupyter_code># make a bubble chart animation
hc_animation = px.scatter(df_hc,
                          x = "Offenses",
                          y = "Incidents",
                          size = "Victims",
                          color = "Race",
                          animation_frame = "Year",
                          title = "Racially Motivated Hate Crime, 2015 to 2019",
                          range_x = [0, 2500],
                          range_y = [0, 2500])
hc_animation
# save the plots as html files
hc_animation.write_html("hc_animation.html")
# download from google colab
files.download("hc_animation.html")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10271546635182999, 'fraction_numerical': 0.025186934277843367, 'mean_word_length': 2.491758241758242, 'pattern_counts': {'":': 3, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '51458', 'license': 'MIT', 'n_tokens_mistral': 857, 'n_tokens_neox': 795, 'n_words': 219, 'path': 'Mini_Project_5.ipynb', 'repo_name': 'ireneliu0106/hate_crime_analysis', 'size': '2541'}