0% found this document useful (0 votes)
30 views5 pages

Thames Valley Crime Data Analysis

Uploaded by

nirmalameh02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Thames Valley Crime Data Analysis

Uploaded by

nirmalameh02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

In [1]:

import pandas as pd

In [29]: data=pd.read_csv("2024-09-thames-valley-street.csv")
data

Out [29]:
Last
Reported LSOA Crime
Crime ID Month Location LSOA code outcome
by name type
category

On or Investigation
Thames Bracknell
2024- near complete;
0 600dc88bebb3499405cf71237c6a89fa4f0e94f51d669d... Valley E01016252 Forest Burglary
09 Winkfield no suspect
Police 001C
Lane identified
On or
Thames Bracknell
2024- near Other Under
1 96339937ce33810cdd4421d7960675e206d9a57e8cddd7... Valley E01016252 Forest
09 Montague theft investigation
Police 001C
Park

Thames On or Bracknell
2024- Other Under
2 48064c2c5c76557638c7d6e9351d59dd3c6a9105a042d5... Valley near Park E01016252 Forest
09 theft investigation
Police Lane 001C
On or Investigation
Thames Bracknell
2024- near Other complete;
3 b88c4f1501e108884efed2d65a1affd624539250adb7c9... Valley E01016252 Forest
09 Lovel theft no suspect
Police 001C
Lane identified

On or Violence
Thames Bracknell
2024- near and Under
4 1b31c1a8a16b1e04baddb82c0b993933388ccf7e8a3936... Valley E01016252 Forest
09 Lovel sexual investigation
Police 001C
Road offences
... ... ... ... ... ... ... ... ...

Thames
2024- No Other Under
15909 d6814bb49b473226149688ad158d39667c0e9cf93ec676... Valley NaN NaN
09 Location crime investigation
Police
Thames
2024- No Other Under
15910 6545cbb38070967441ff0ab6e11d68fedf9ae473efe30a... Valley NaN NaN
09 Location crime investigation
Police

Thames Awaiting
2024- No Other
15911 a36eb3c08d3dcfc613037003f57796630a1dd5edf6c9ed... Valley NaN NaN court
09 Location crime
Police outcome
Investigation
Thames
2024- No Other complete;
15912 4e8cf7cb5dede7bb61ed58559ca78ec6db80b0511c3465... Valley NaN NaN
09 Location crime no suspect
Police
identified

Thames Unable to
2024- No Other
15913 dd5a226b82a5658ef985e246324d50eb7c967a1fe7eba4... Valley NaN NaN prosecute
09 Location crime
Police suspect

15914 rows × 8 columns

Data Overview
In [13]:
# Check Data Types
print(data.dtypes)

Crime ID object
Month object
Reported by object
Location object
LSOA code object
LSOA name object
Crime type object
Last outcome category object
dtype: object

In [15]:
# Check for Missing Values
print(data.isnull().sum())

Crime ID 1512
Month 0
Reported by 0
Location 0
LSOA code 333
LSOA name 333
Crime type 0
Last outcome category 1512
dtype: int64

In [25]:
# Removing Null values from dataset
data.dropna(subset=['Crime ID'], inplace=True)
data.dropna(subset=['LSOA code'], inplace=True)
data.dropna(subset=['LSOA name'], inplace=True)
data.dropna(subset=['Last outcome category'], inplace=True)
In [27]:
data

Out [27]:
Last
Reported Crime
Crime ID Month Location LSOA code LSOA name outcome
by type
category

On or Investigation
Thames Bracknell
2024- near complete;
0 600dc88bebb3499405cf71237c6a89fa4f0e94f51d669d... Valley E01016252 Forest Burglary
09 Winkfield no suspect
Police 001C
Lane identified
On or
Thames Bracknell
2024- near Other Under
1 96339937ce33810cdd4421d7960675e206d9a57e8cddd7... Valley E01016252 Forest
09 Montague theft investigation
Police 001C
Park

Thames On or Bracknell
2024- Other Under
2 48064c2c5c76557638c7d6e9351d59dd3c6a9105a042d5... Valley near Park E01016252 Forest
09 theft investigation
Police Lane 001C
On or Investigation
Thames Bracknell
2024- near Other complete;
3 b88c4f1501e108884efed2d65a1affd624539250adb7c9... Valley E01016252 Forest
09 Lovel theft no suspect
Police 001C
Lane identified

On or Violence
Thames Bracknell
2024- near and Under
4 1b31c1a8a16b1e04baddb82c0b993933388ccf7e8a3936... Valley E01016252 Forest
09 Lovel sexual investigation
Police 001C
Road offences
... ... ... ... ... ... ... ... ...

On or Investigation
Thames
2024- near Wokingham Other complete;
15576 885751ac442a3fc0986990d3560163d8583f04bb17668f... Valley E01016707
09 Frensham 020C theft no suspect
Police
Road identified
On or Violence
Thames Unable to
2024- near Wokingham and
15577 017181b524fa94ed54e287c474a5b1b8f7f4dbd5c616dc... Valley E01016707 prosecute
09 Keats 020C sexual
Police suspect
Way offences

On or Investigation
Thames
2024- near The Wokingham Vehicle complete;
15578 a051998aa292cb3247ab4edafca727c1730a7205564367... Valley E01016708
09 Devil'S 020D crime no suspect
Police
Highway identified
On or
Thames
2024- near Wokingham Public Under
15579 df9a70642d0a6367afc606c425f0d05b27ad97f1d1c9ae... Valley E01016709
09 Butler 020E order investigation
Police
Road

On or Violence
Thames
2024- near Wokingham and Under
15580 a69c1481565d90268d5837fa23608b0143a467146ccca4... Valley E01016709
09 Wiltshire 020E sexual investigation
Police
Avenue offences

14096 rows × 8 columns

Statistical Summary
In [31]:
# Descriptive Statistics for Numerical Columns
print(data.describe())

Crime ID Month \
count 14402 15914
unique 14397 1
top 7f4757e9c065c9990940e66782f8a667b9887a8c51ae29... 2024-09
freq 2 15914

Reported by Location LSOA code LSOA name \


count 15914 15914 15581 15581
unique 1 6048 1457 1457
top Thames Valley Police On or near Supermarket E01033415 Reading 019B
freq 15914 829 227 227

Crime type Last outcome category


count 15914 14402
unique 14 10
top Violence and sexual offences Under investigation
freq 5876 8894

In [33]:
# Crime type count
crime_counts = data['Crime type'].value_counts()
print(crime_counts)

Crime type
Violence and sexual offences 5876
Shoplifting 1583
Anti-social behaviour 1512
Public order 1246
Other theft 1220
Vehicle crime 1123
Criminal damage and arson 1111
Drugs 527
Burglary 519
Bicycle theft 400
Other crime 315
Theft from the person 210
Robbery 151
Possession of weapons 121
Name: count, dtype: int64

In [37]:
# Status of each crime
crime_outcome_counts = data.groupby(['Crime type', 'Last outcome category']).size().reset_index(name='Count')
print(crime_outcome_counts)

Crime type \
0 Bicycle theft
1 Bicycle theft
2 Bicycle theft
3 Burglary
4 Burglary
.. ...
77 Violence and sexual offences
78 Violence and sexual offences
79 Violence and sexual offences
80 Violence and sexual offences
81 Violence and sexual offences

Last outcome category Count


0 Investigation complete; no suspect identified 284
1 Unable to prosecute suspect 15
2 Under investigation 101
3 Awaiting court outcome 6
4 Investigation complete; no suspect identified 176
.. ... ...
77 Investigation complete; no suspect identified 372
78 Local resolution 21
79 Offender given a caution 10
80 Unable to prosecute suspect 1061
81 Under investigation 4200

[82 rows x 3 columns]

Visual analysis
In [41]: # Plot stacked bar chart
crime_outcome_counts = data.groupby(['Crime type', 'Last outcome category']).size().unstack(fill_value=0)

crime_outcome_counts.plot(kind='bar', stacked=True, figsize=(12, 8), colormap='viridis')


plt.title('Count of Each Crime Type with Last Outcome Category')
plt.xlabel('Crime Type')
plt.ylabel('Count')
plt.legend(title='Last Outcome Category', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()

---------------------------------------------------------------------------NameError Traceback (most recent call las


4 # Plot stacked bar chart
5 crime_outcome_counts.plot(kind='bar', stacked=True, figsize=(12, 8), colormap='viridis')
----> 6 plt.title('Count of Each Crime Type with Last Outcome Category')
7 plt.xlabel('Crime Type')
8 plt.ylabel('Count')
NameError: name 'plt' is not defined
Time series
In [61]:
data=pd.read_csv("2024-09-thames-valley-street.csv")
data['Month'] = pd.to_datetime(data['Month'], format='%Y-%m')

# Group by 'Month' and 'Crime type' to get the count of each crime type per month
crime_counts = data.groupby(['Month', 'Crime type']).size().reset_index(name='Crime Count')

# Display the resulting time series data


print(crime_counts.head())

Month Crime type Crime Count


0 2024-09-01 Anti-social behaviour 1512
1 2024-09-01 Bicycle theft 400
2 2024-09-01 Burglary 519
3 2024-09-01 Criminal damage and arson 1111
4 2024-09-01 Drugs 527

In [74]:
# Pivot Table
pivot_table = data.pivot_table(
index=['Location'],
columns=['Crime type'],
aggfunc='size',
fill_value=0
)
print(pivot_table)

Crime type Anti-social behaviour Bicycle theft Burglary \


Location
No Location 27 4 3
On or near A308 1 0 0
On or near A3095 0 0 0
On or near A322 0 0 0
On or near A329 2 0 0
... ... ... ...
On or near York Road 0 1 0
On or near Young Crescent 0 0 0
On or near Zenith Avenue 0 0 0
On or near Zinzan Street 0 0 0
On or near Zoe Street 0 0 0

Crime type Criminal damage and arson Drugs Other crime \


Location
No Location 15 21 10
On or near A308 0 0 0
On or near A3095 0 0 0
On or near A322 1 0 0
On or near A329 1 0 0
... ... ... ...
On or near York Road 1 0 0
On or near Young Crescent 0 0 0
On or near Zenith Avenue 1 0 0
On or near Zinzan Street 1 0 2
On or near Zoe Street 0 0 0

Crime type Other theft Possession of weapons Public order \


Location
No Location 20 2 26
On or near A308 0 0 0
On or near A3095 0 0 0
On or near A322 0 0 0
On or near A329 1 0 0
... ... ... ...
On or near York Road 2 0 0
On or near Young Crescent 0 0 0
On or near Zenith Avenue 0 0 0
On or near Zinzan Street 0 0 0
On or near Zoe Street 0 0 0

Crime type Robbery Shoplifting Theft from the person \


Location
No Location 3 22 4
On or near A308 0 0 0
On or near A3095 0 0 0
On or near A322 0 0 0
On or near A329 0 8 0
... ... ... ...
On or near York Road 0 0 0
On or near Young Crescent 0 0 0
On or near Zenith Avenue 0 0 0
On or near Zinzan Street 0 0 0
On or near Zoe Street 0 0 0

Crime type Vehicle crime Violence and sexual offences


Location
No Location 16 160
On or near A308 0 0
On or near A3095 1 0
On or near A322 0 0
On or near A329 0 1
... ... ...
On or near York Road 0 1
On or near Young Crescent 0 2
On or near Zenith Avenue 0 0
On or near Zinzan Street 1 2
On or near Zoe Street 0 1

[6048 rows x 14 columns]

In [76]:
# Group by Location and Crime Type
location_crime_aggregated = data.groupby(['Location', 'Crime type']).size().reset_index(name='Crime Count')
print(location_crime_aggregated)

Location Crime type Crime Count


0 No Location Anti-social behaviour 27
1 No Location Bicycle theft 4
2 No Location Burglary 3
3 No Location Criminal damage and arson 15
4 No Location Drugs 21
... ... ... ...
9232 On or near Zinzan Street Criminal damage and arson 1
9233 On or near Zinzan Street Other crime 2
9234 On or near Zinzan Street Vehicle crime 1
9235 On or near Zinzan Street Violence and sexual offences 2
9236 On or near Zoe Street Violence and sexual offences 1

[9237 rows x 3 columns]

In [ ]:

You might also like