Crímenes en Filadelfia.

Importar Librerías.

In [1]:

Cargar Datos para crear un DataFrame.

In [2]:

Ver las primeras filas.

In [17]:
Out[17]:
Dc_Dist Psa Dispatch_Date_Time Dispatch_Date Dispatch_Time Hour Dc_Key Location_Block UCR_General Text_General_Code Police_Districts Month Lon Lat cuantos
0 18 3 2009-10-02 14:24:00 2009-10-02 14:24:00 14 200918067518 S 38TH ST / MARKETUT ST 800.0 Other Assaults NaN 2009-10 NaN NaN 1
1 14 1 2009-05-10 00:55:00 2009-05-10 00:55:00 0 200914033994 8500 BLOCK MITCH 2600.0 All Other Offenses NaN 2009-05 NaN NaN 1
2 25 J 2009-08-07 15:40:00 2009-08-07 15:40:00 15 200925083199 6TH CAMBRIA 800.0 Other Assaults NaN 2009-08 NaN NaN 1
3 35 D 2009-07-19 01:09:00 2009-07-19 01:09:00 1 200935061008 5500 BLOCK N 5TH ST 1500.0 Weapon Violations 20.0 2009-07 -75.130477 40.036389 1
4 9 R 2009-06-25 00:14:00 2009-06-25 00:14:00 0 200909030511 1800 BLOCK WYLIE ST 2600.0 All Other Offenses 8.0 2009-06 -75.166350 39.969532 1

Contar la cantidad de registros.

In [13]:
Out[13]:
2237605

Resumir el conjunto de datos en 5 formas distintas.

1. Cantidad que se registra por cada tipo de crimen.

In [36]:
Cantidad de crímenes por tipo

All Other Offenses                         437581
Other Assaults                             277332
Thefts                                     257923
Vandalism/Criminal Mischief                200345
Theft from Vehicle                         171135
Narcotic / Drug Law Violations             137448
Fraud                                      114416
Recovered Stolen Motor Vehicle              95282
Burglary Residential                        94143
Aggravated Assault No Firearm               68989
DRIVING UNDER THE INFLUENCE                 53721
Robbery No Firearm                          51919
Motor Vehicle Theft                         46517
Robbery Firearm                             40577
Disorderly Conduct                          40137
Aggravated Assault Firearm                  27934
Burglary Non-Residential                    23276
Weapon Violations                           19092
Other Sex Offenses (Not Commercialized)     15304
Prostitution and Commercialized Vice        12854
Rape                                        11852
Vagrancy/Loitering                           6776
Arson                                        5684
Liquor Law Violations                        5439
Forgery and Counterfeiting                   4843
Embezzlement                                 4807
Public Drunkenness                           4619
Homicide - Criminal                          3442
Offenses Against Family and Children         1794
Gambling Violations                           921
Receiving Stolen Property                     786
NaN                                           663
Homicide - Justifiable                         42
Homicide - Gross Negligence                    12
Name: Text_General_Code, dtype: int64

2. Cantidad de tipos de crímenes por bloque de ubicación

In [5]:
In [98]:
 Conteo de crímenes por bloque de ubicación 

Text_General_Code   Location_Block                        
Thefts              1000 BLOCK MARKET ST                      3287
                    4600 BLOCK E ROOSEVELT BLVD               2909
                    1300 BLOCK MARKET ST                      2152
All Other Offenses  0 BLOCK N 52ND ST                         2142
Thefts              1600 BLOCK S CHRISTOPHER COLUMBUS BLVD    1644
Name: Location_Block, dtype: int64

3. Conteo de crímenes por mes

In [99]:
 Conteo de crímenes por mes 

Out[99]:
Dc_Dist Psa Dispatch_Date_Time Dispatch_Date Dispatch_Time Hour Dc_Key Location_Block UCR_General Police_Districts Lon Lat cuantos
Text_General_Code Month
All Other Offenses 2006-08 5404 5404 5404 5404 5404 5404 5404 5404 5404 5381 5383 5383 5404
2006-06 5061 5061 5061 5061 5061 5061 5061 5061 5061 5014 5020 5020 5061
2006-07 4980 4980 4980 4980 4980 4980 4980 4980 4980 4956 4959 4959 4980
2008-08 4913 4913 4913 4913 4913 4913 4913 4913 4913 4886 4897 4897 4913
2008-07 4792 4792 4792 4792 4792 4792 4792 4792 4792 4757 4780 4780 4792

Importando librerías matemáticas

In [9]:

4. Computar la similaridad entre entidades

In [30]:
Out[30]:
2237605
In [ ]:
In [34]:
In [35]:
 Mostrar los datos en el espacio vectorial 

Out[35]:
Dc_Key 199812085407 199814043321 199816011336 199819107021 199822006037 199822061421 199826012549 199826025430 199835131136 199835141918 ... 201777001386 201777001388 201777001407 201777001414 201777001415 201777001421 201777001440 201777001442 201777001444 201777001445
Text_General_Code
NaN 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
Aggravated Assault Firearm 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
Aggravated Assault No Firearm 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
All Other Offenses 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 1 0
Arson 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0

5 rows × 2237605 columns

In [42]:
Out[42]:
(34, 2237605)

5. Visualizar en un histograma

In [46]:
 Mostrar en histograma los datos del espacio vectorial 

Out[46]:
<matplotlib.axes._subplots.AxesSubplot at 0x231048fac50>