<jupyter_start><jupyter_text>This dataset analyzes information on sex crimes in Los Angeles during the year 2022 The data is only as good as the data in the database<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df = pd.read_csv('Crime_Data_from_2020_to_Present.csv')
df['Date'] = pd.to_datetime(df['DATE OCC'])
df = df.loc[(df['Date'].dt.year==2022)]# & (df['Date'].dt.month== 8)] 
df.head()

df.shape
df.isna().any()[lambda x: x]
df.columns[df.isnull().any()]
df['Crm Cd Desc'].value_counts().iloc[:10].sort_values().plot(kind="barh", title = "Types of Crimes")
df['AREA NAME'].value_counts().sort_values().plot(kind="barh", color = '#1ABC9C', title = 'Total of Crime Events by Area')
sex_crimes = df[df['Crm Cd Desc'].str.contains('SEX CRIMES|RAPE')].copy()
sex_crimes.head()
sex_crimes['Crm Cd Desc'].value_counts().sort_values().plot(kind="barh", color = '#ff5733', title = 'Sex Crimes by Type in 2022')
sex_crimes['AREA NAME'].value_counts().sort_values().plot(kind="barh", color = '#ff5733', title = 'Sex Crimes by Area in 2022')
sex_crimes['Vict Sex'].value_counts().sort_values().plot(kind="bar", color = '#ffdd33', title = 'Sex Crimes by Gender in 2022')
sex_crimes['Vict Descent'].value_counts().sort_values().plot(kind="bar", color = '#33ffa2', title = 'Sex Crimes by Race in 2022')<jupyter_output><empty_output><jupyter_text>Let's categorize the age field<jupyter_code>sex_crimes.loc[sex_crimes['Vict Age']<=17, 'age_group'] = 'less than 18'
sex_crimes.loc[sex_crimes['age_group']=='less than 18', 'age_sort'] = 1.0
sex_crimes.loc[sex_crimes['Vict Age'].between(18,28), 'age_group'] = '18 - 28'
sex_crimes.loc[sex_crimes['age_group']=='18 - 28', 'age_sort'] = 2
sex_crimes.loc[sex_crimes['Vict Age'].between(29,39), 'age_group'] = '29 - 39'
sex_crimes.loc[sex_crimes['age_group']=='29 - 39', 'age_sort'] = 3
sex_crimes.loc[sex_crimes['Vict Age'].between(40,49), 'age_group'] = '40 - 49'
sex_crimes.loc[sex_crimes['age_group']=='40 - 49', 'age_sort'] = 4
sex_crimes.loc[sex_crimes['Vict Age'].between(50,59), 'age_group'] = '50 - 59'
sex_crimes.loc[sex_crimes['age_group']=='50 - 59', 'age_sort'] = 5
sex_crimes.loc[sex_crimes['Vict Age'].between(60,69), 'age_group'] = '60 - 69'
sex_crimes.loc[sex_crimes['age_group']=='60 - 69', 'age_sort'] = 6
sex_crimes.loc[sex_crimes['Vict Age']>=70, 'age_group'] = 'older than 69'
sex_crimes.loc[sex_crimes['age_group']=='70 - 200', 'age_sort'] = 7
sex_crimes.tail(2)
sex_crimes = sex_crimes.sort_values('age_sort')
sex_crimes.head()



sns.set_theme(style="darkgrid")
day_order = ["less than 18", '18 - 28', '29 - 39', '40 - 49', '50 - 59']#, '60 - 69', 'older than 69']
sns.countplot(x = "age_group", data = sex_crimes, order = day_order, palette="Set2").set(title='Sex Crimes by Age')
plt.xticks(rotation=45)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19698562916228532, 'fraction_numerical': 0.055029793200140203, 'mean_word_length': 6.862258953168044, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '134330', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1116, 'n_words': 225, 'path': '.ipynb_checkpoints/revw-checkpoint.ipynb', 'repo_name': 'pattyjula/datascience', 'size': '2853'}