2023-programowanie-w-pythonie/zajecia2/zad_01.ipynb
Maksymilian Stachowiak 92dca8796c rozwiazanka
2023-11-26 09:12:43 +01:00

1208 lines
42 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Zaimportuj bibliotkę pandas jako pd."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Wczytaj zbiór danych `311.csv` do zniennej data."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('./311.csv', low_memory=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Wyświetl 5 pierwszych wierszy z data."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unique Key</th>\n",
" <th>Created Date</th>\n",
" <th>Closed Date</th>\n",
" <th>Agency</th>\n",
" <th>Agency Name</th>\n",
" <th>Complaint Type</th>\n",
" <th>Descriptor</th>\n",
" <th>Location Type</th>\n",
" <th>Incident Zip</th>\n",
" <th>Incident Address</th>\n",
" <th>...</th>\n",
" <th>Bridge Highway Name</th>\n",
" <th>Bridge Highway Direction</th>\n",
" <th>Road Ramp</th>\n",
" <th>Bridge Highway Segment</th>\n",
" <th>Garage Lot Name</th>\n",
" <th>Ferry Direction</th>\n",
" <th>Ferry Terminal Name</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>Location</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>26589651</td>\n",
" <td>10/31/2013 02:08:41 AM</td>\n",
" <td>NaN</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Street/Sidewalk</td>\n",
" <td>Loud Talking</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11432</td>\n",
" <td>90-03 169 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.708275</td>\n",
" <td>-73.791604</td>\n",
" <td>(40.70827532593202, -73.79160395779721)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>26593698</td>\n",
" <td>10/31/2013 02:01:04 AM</td>\n",
" <td>NaN</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Illegal Parking</td>\n",
" <td>Commercial Overnight Parking</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11378</td>\n",
" <td>58 AVENUE</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.721041</td>\n",
" <td>-73.909453</td>\n",
" <td>(40.721040535628305, -73.90945306791765)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26594139</td>\n",
" <td>10/31/2013 02:00:24 AM</td>\n",
" <td>10/31/2013 02:40:32 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Commercial</td>\n",
" <td>Loud Music/Party</td>\n",
" <td>Club/Bar/Restaurant</td>\n",
" <td>10032</td>\n",
" <td>4060 BROADWAY</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.843330</td>\n",
" <td>-73.939144</td>\n",
" <td>(40.84332975466513, -73.93914371913482)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>26595721</td>\n",
" <td>10/31/2013 01:56:23 AM</td>\n",
" <td>10/31/2013 02:21:48 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Vehicle</td>\n",
" <td>Car/Truck Horn</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>10023</td>\n",
" <td>WEST 72 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.778009</td>\n",
" <td>-73.980213</td>\n",
" <td>(40.7780087446372, -73.98021349023975)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>26590930</td>\n",
" <td>10/31/2013 01:53:44 AM</td>\n",
" <td>NaN</td>\n",
" <td>DOHMH</td>\n",
" <td>Department of Health and Mental Hygiene</td>\n",
" <td>Rodent</td>\n",
" <td>Condition Attracting Rodents</td>\n",
" <td>Vacant Lot</td>\n",
" <td>10027</td>\n",
" <td>WEST 124 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.807691</td>\n",
" <td>-73.947387</td>\n",
" <td>(40.80769092704951, -73.94738703491433)</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 52 columns</p>\n",
"</div>"
],
"text/plain": [
" Unique Key Created Date Closed Date Agency \\\n",
"0 26589651 10/31/2013 02:08:41 AM NaN NYPD \n",
"1 26593698 10/31/2013 02:01:04 AM NaN NYPD \n",
"2 26594139 10/31/2013 02:00:24 AM 10/31/2013 02:40:32 AM NYPD \n",
"3 26595721 10/31/2013 01:56:23 AM 10/31/2013 02:21:48 AM NYPD \n",
"4 26590930 10/31/2013 01:53:44 AM NaN DOHMH \n",
"\n",
" Agency Name Complaint Type \\\n",
"0 New York City Police Department Noise - Street/Sidewalk \n",
"1 New York City Police Department Illegal Parking \n",
"2 New York City Police Department Noise - Commercial \n",
"3 New York City Police Department Noise - Vehicle \n",
"4 Department of Health and Mental Hygiene Rodent \n",
"\n",
" Descriptor Location Type Incident Zip \\\n",
"0 Loud Talking Street/Sidewalk 11432 \n",
"1 Commercial Overnight Parking Street/Sidewalk 11378 \n",
"2 Loud Music/Party Club/Bar/Restaurant 10032 \n",
"3 Car/Truck Horn Street/Sidewalk 10023 \n",
"4 Condition Attracting Rodents Vacant Lot 10027 \n",
"\n",
" Incident Address ... Bridge Highway Name Bridge Highway Direction \\\n",
"0 90-03 169 STREET ... NaN NaN \n",
"1 58 AVENUE ... NaN NaN \n",
"2 4060 BROADWAY ... NaN NaN \n",
"3 WEST 72 STREET ... NaN NaN \n",
"4 WEST 124 STREET ... NaN NaN \n",
"\n",
" Road Ramp Bridge Highway Segment Garage Lot Name Ferry Direction \\\n",
"0 NaN NaN NaN NaN \n",
"1 NaN NaN NaN NaN \n",
"2 NaN NaN NaN NaN \n",
"3 NaN NaN NaN NaN \n",
"4 NaN NaN NaN NaN \n",
"\n",
" Ferry Terminal Name Latitude Longitude \\\n",
"0 NaN 40.708275 -73.791604 \n",
"1 NaN 40.721041 -73.909453 \n",
"2 NaN 40.843330 -73.939144 \n",
"3 NaN 40.778009 -73.980213 \n",
"4 NaN 40.807691 -73.947387 \n",
"\n",
" Location \n",
"0 (40.70827532593202, -73.79160395779721) \n",
"1 (40.721040535628305, -73.90945306791765) \n",
"2 (40.84332975466513, -73.93914371913482) \n",
"3 (40.7780087446372, -73.98021349023975) \n",
"4 (40.80769092704951, -73.94738703491433) \n",
"\n",
"[5 rows x 52 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Wyświetl nazwy kolumn."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Unique Key', 'Created Date', 'Closed Date', 'Agency', 'Agency Name',\n",
" 'Complaint Type', 'Descriptor', 'Location Type', 'Incident Zip',\n",
" 'Incident Address', 'Street Name', 'Cross Street 1', 'Cross Street 2',\n",
" 'Intersection Street 1', 'Intersection Street 2', 'Address Type',\n",
" 'City', 'Landmark', 'Facility Type', 'Status', 'Due Date',\n",
" 'Resolution Action Updated Date', 'Community Board', 'Borough',\n",
" 'X Coordinate (State Plane)', 'Y Coordinate (State Plane)',\n",
" 'Park Facility Name', 'Park Borough', 'School Name', 'School Number',\n",
" 'School Region', 'School Code', 'School Phone Number', 'School Address',\n",
" 'School City', 'School State', 'School Zip', 'School Not Found',\n",
" 'School or Citywide Complaint', 'Vehicle Type', 'Taxi Company Borough',\n",
" 'Taxi Pick Up Location', 'Bridge Highway Name',\n",
" 'Bridge Highway Direction', 'Road Ramp', 'Bridge Highway Segment',\n",
" 'Garage Lot Name', 'Ferry Direction', 'Ferry Terminal Name', 'Latitude',\n",
" 'Longitude', 'Location'],\n",
" dtype='object')"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Wyświetl ile nasz zbiór danych ma kolumn i wierszy."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(111069, 52)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. Wyświetl kolumnę 'City' z powyższego zbioru danych."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 JAMAICA\n",
"1 MASPETH\n",
"2 NEW YORK\n",
"3 NEW YORK\n",
"4 NEW YORK\n",
" ... \n",
"111064 BROOKLYN\n",
"111065 JAMAICA\n",
"111066 NEW YORK\n",
"111067 BROOKLYN\n",
"111068 BROOKLYN\n",
"Name: City, Length: 111069, dtype: object"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['City']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"7. Wyświetl jakie wartoścu przyjmuje kolumna 'City'."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['JAMAICA', 'MASPETH', 'NEW YORK', ..., 'NEW YORK', 'BROOKLYN',\n",
" 'BROOKLYN'], dtype=object)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['City'].values"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"8. Zlicz wartości w kolumnie `City`."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"City\n",
"BROOKLYN 31662\n",
"NEW YORK 22664\n",
"BRONX 18438\n",
"STATEN ISLAND 4766\n",
"Jamaica 1521\n",
" ... \n",
"BELLEVILLE 1\n",
"WOODBURY 1\n",
"BOHIEMA 1\n",
"CENTRAL ISLIP 1\n",
"NEWARK AIRPORT 1\n",
"Name: count, Length: 142, dtype: int64"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['City'].value_counts()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"9. Wyświetl tylko pierwsze 4 wiersze z wcześniejszego polecenia."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"City\n",
"BROOKLYN 31662\n",
"NEW YORK 22664\n",
"BRONX 18438\n",
"STATEN ISLAND 4766\n",
"Name: count, dtype: int64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['City'].value_counts().head(4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12215"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['City'].isna().sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"11. Wyświetl data.info()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 111069 entries, 0 to 111068\n",
"Data columns (total 52 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Unique Key 111069 non-null int64 \n",
" 1 Created Date 111069 non-null object \n",
" 2 Closed Date 60270 non-null object \n",
" 3 Agency 111069 non-null object \n",
" 4 Agency Name 111069 non-null object \n",
" 5 Complaint Type 111069 non-null object \n",
" 6 Descriptor 110613 non-null object \n",
" 7 Location Type 79022 non-null object \n",
" 8 Incident Zip 98807 non-null object \n",
" 9 Incident Address 84441 non-null object \n",
" 10 Street Name 84432 non-null object \n",
" 11 Cross Street 1 84728 non-null object \n",
" 12 Cross Street 2 84005 non-null object \n",
" 13 Intersection Street 1 19364 non-null object \n",
" 14 Intersection Street 2 19366 non-null object \n",
" 15 Address Type 102247 non-null object \n",
" 16 City 98854 non-null object \n",
" 17 Landmark 95 non-null object \n",
" 18 Facility Type 19104 non-null object \n",
" 19 Status 111069 non-null object \n",
" 20 Due Date 39239 non-null object \n",
" 21 Resolution Action Updated Date 96507 non-null object \n",
" 22 Community Board 111069 non-null object \n",
" 23 Borough 111069 non-null object \n",
" 24 X Coordinate (State Plane) 98143 non-null float64\n",
" 25 Y Coordinate (State Plane) 98143 non-null float64\n",
" 26 Park Facility Name 111069 non-null object \n",
" 27 Park Borough 111069 non-null object \n",
" 28 School Name 111069 non-null object \n",
" 29 School Number 111048 non-null object \n",
" 30 School Region 110524 non-null object \n",
" 31 School Code 110524 non-null object \n",
" 32 School Phone Number 111069 non-null object \n",
" 33 School Address 111069 non-null object \n",
" 34 School City 111069 non-null object \n",
" 35 School State 111069 non-null object \n",
" 36 School Zip 111069 non-null object \n",
" 37 School Not Found 38984 non-null object \n",
" 38 School or Citywide Complaint 0 non-null float64\n",
" 39 Vehicle Type 99 non-null object \n",
" 40 Taxi Company Borough 117 non-null object \n",
" 41 Taxi Pick Up Location 1059 non-null object \n",
" 42 Bridge Highway Name 185 non-null object \n",
" 43 Bridge Highway Direction 185 non-null object \n",
" 44 Road Ramp 180 non-null object \n",
" 45 Bridge Highway Segment 219 non-null object \n",
" 46 Garage Lot Name 49 non-null object \n",
" 47 Ferry Direction 24 non-null object \n",
" 48 Ferry Terminal Name 70 non-null object \n",
" 49 Latitude 98143 non-null float64\n",
" 50 Longitude 98143 non-null float64\n",
" 51 Location 98143 non-null object \n",
"dtypes: float64(5), int64(1), object(46)\n",
"memory usage: 44.1+ MB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"12. Wyświetl tylko kolumny Borough i Agency i tylko 5 ostatnich linii."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Borough</th>\n",
" <th>Agency</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>111064</th>\n",
" <td>BROOKLYN</td>\n",
" <td>DPR</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111065</th>\n",
" <td>QUEENS</td>\n",
" <td>NYPD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111066</th>\n",
" <td>MANHATTAN</td>\n",
" <td>NYPD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111067</th>\n",
" <td>BROOKLYN</td>\n",
" <td>NYPD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111068</th>\n",
" <td>BROOKLYN</td>\n",
" <td>NYPD</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Agency\n",
"111064 BROOKLYN DPR\n",
"111065 QUEENS NYPD\n",
"111066 MANHATTAN NYPD\n",
"111067 BROOKLYN NYPD\n",
"111068 BROOKLYN NYPD"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[['Borough','Agency']].tail(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"13. Wyświetl tylko te dane, dla których wartość z kolumny Agency jest równa\n",
"NYPD. Zlicz ile jest takich przykładów.\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Agency\n",
"False 95774\n",
"True 15295\n",
"Name: count, dtype: int64"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Agency'].eq('NYPD').value_counts()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"14. Wyświetl wartość minimalną i maksymalną z kolumny Longitude."
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-74.25443731808713\n",
"-73.70127761473603\n"
]
}
],
"source": [
"print(df['Longitude'].min())\n",
"print(df['Longitude'].max())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"15. Dodaj kolumne diff, która powstanie przez sumowanie kolumn Longitude i Latitude."
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unique Key</th>\n",
" <th>Created Date</th>\n",
" <th>Closed Date</th>\n",
" <th>Agency</th>\n",
" <th>Agency Name</th>\n",
" <th>Complaint Type</th>\n",
" <th>Descriptor</th>\n",
" <th>Location Type</th>\n",
" <th>Incident Zip</th>\n",
" <th>Incident Address</th>\n",
" <th>...</th>\n",
" <th>Bridge Highway Direction</th>\n",
" <th>Road Ramp</th>\n",
" <th>Bridge Highway Segment</th>\n",
" <th>Garage Lot Name</th>\n",
" <th>Ferry Direction</th>\n",
" <th>Ferry Terminal Name</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>Location</th>\n",
" <th>diff</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>26589651</td>\n",
" <td>10/31/2013 02:08:41 AM</td>\n",
" <td>NaN</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Street/Sidewalk</td>\n",
" <td>Loud Talking</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11432</td>\n",
" <td>90-03 169 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.708275</td>\n",
" <td>-73.791604</td>\n",
" <td>(40.70827532593202, -73.79160395779721)</td>\n",
" <td>-33.083329</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>26593698</td>\n",
" <td>10/31/2013 02:01:04 AM</td>\n",
" <td>NaN</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Illegal Parking</td>\n",
" <td>Commercial Overnight Parking</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11378</td>\n",
" <td>58 AVENUE</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.721041</td>\n",
" <td>-73.909453</td>\n",
" <td>(40.721040535628305, -73.90945306791765)</td>\n",
" <td>-33.188413</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>26594139</td>\n",
" <td>10/31/2013 02:00:24 AM</td>\n",
" <td>10/31/2013 02:40:32 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Commercial</td>\n",
" <td>Loud Music/Party</td>\n",
" <td>Club/Bar/Restaurant</td>\n",
" <td>10032</td>\n",
" <td>4060 BROADWAY</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.843330</td>\n",
" <td>-73.939144</td>\n",
" <td>(40.84332975466513, -73.93914371913482)</td>\n",
" <td>-33.095814</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>26595721</td>\n",
" <td>10/31/2013 01:56:23 AM</td>\n",
" <td>10/31/2013 02:21:48 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Vehicle</td>\n",
" <td>Car/Truck Horn</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>10023</td>\n",
" <td>WEST 72 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.778009</td>\n",
" <td>-73.980213</td>\n",
" <td>(40.7780087446372, -73.98021349023975)</td>\n",
" <td>-33.202205</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>26590930</td>\n",
" <td>10/31/2013 01:53:44 AM</td>\n",
" <td>NaN</td>\n",
" <td>DOHMH</td>\n",
" <td>Department of Health and Mental Hygiene</td>\n",
" <td>Rodent</td>\n",
" <td>Condition Attracting Rodents</td>\n",
" <td>Vacant Lot</td>\n",
" <td>10027</td>\n",
" <td>WEST 124 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.807691</td>\n",
" <td>-73.947387</td>\n",
" <td>(40.80769092704951, -73.94738703491433)</td>\n",
" <td>-33.139696</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111064</th>\n",
" <td>26426013</td>\n",
" <td>10/04/2013 12:01:13 AM</td>\n",
" <td>10/07/2013 04:07:16 PM</td>\n",
" <td>DPR</td>\n",
" <td>Department of Parks and Recreation</td>\n",
" <td>Maintenance or Facility</td>\n",
" <td>Structure - Outdoors</td>\n",
" <td>Park</td>\n",
" <td>11213</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111065</th>\n",
" <td>26428083</td>\n",
" <td>10/04/2013 12:01:05 AM</td>\n",
" <td>10/04/2013 02:13:50 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Illegal Parking</td>\n",
" <td>Posted Parking Sign Violation</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11434</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.656160</td>\n",
" <td>-73.767353</td>\n",
" <td>(40.656160351546845, -73.76735262738222)</td>\n",
" <td>-33.111192</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111066</th>\n",
" <td>26428987</td>\n",
" <td>10/04/2013 12:00:45 AM</td>\n",
" <td>10/04/2013 01:25:01 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Street/Sidewalk</td>\n",
" <td>Loud Talking</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>10016</td>\n",
" <td>344 EAST 28 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.740295</td>\n",
" <td>-73.976952</td>\n",
" <td>(40.740295354643706, -73.97695165980414)</td>\n",
" <td>-33.236656</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111067</th>\n",
" <td>26426115</td>\n",
" <td>10/04/2013 12:00:28 AM</td>\n",
" <td>10/04/2013 04:17:32 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Noise - Commercial</td>\n",
" <td>Loud Talking</td>\n",
" <td>Club/Bar/Restaurant</td>\n",
" <td>11226</td>\n",
" <td>1233 FLATBUSH AVENUE</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.640182</td>\n",
" <td>-73.955306</td>\n",
" <td>(40.64018174662485, -73.95530566958138)</td>\n",
" <td>-33.315124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111068</th>\n",
" <td>26428033</td>\n",
" <td>10/04/2013 12:00:10 AM</td>\n",
" <td>10/04/2013 01:20:52 AM</td>\n",
" <td>NYPD</td>\n",
" <td>New York City Police Department</td>\n",
" <td>Blocked Driveway</td>\n",
" <td>Partial Access</td>\n",
" <td>Street/Sidewalk</td>\n",
" <td>11236</td>\n",
" <td>1259 EAST 94 STREET</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>40.640024</td>\n",
" <td>-73.900717</td>\n",
" <td>(40.640024057399216, -73.90071711703163)</td>\n",
" <td>-33.260693</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>111069 rows × 53 columns</p>\n",
"</div>"
],
"text/plain": [
" Unique Key Created Date Closed Date Agency \\\n",
"0 26589651 10/31/2013 02:08:41 AM NaN NYPD \n",
"1 26593698 10/31/2013 02:01:04 AM NaN NYPD \n",
"2 26594139 10/31/2013 02:00:24 AM 10/31/2013 02:40:32 AM NYPD \n",
"3 26595721 10/31/2013 01:56:23 AM 10/31/2013 02:21:48 AM NYPD \n",
"4 26590930 10/31/2013 01:53:44 AM NaN DOHMH \n",
"... ... ... ... ... \n",
"111064 26426013 10/04/2013 12:01:13 AM 10/07/2013 04:07:16 PM DPR \n",
"111065 26428083 10/04/2013 12:01:05 AM 10/04/2013 02:13:50 AM NYPD \n",
"111066 26428987 10/04/2013 12:00:45 AM 10/04/2013 01:25:01 AM NYPD \n",
"111067 26426115 10/04/2013 12:00:28 AM 10/04/2013 04:17:32 AM NYPD \n",
"111068 26428033 10/04/2013 12:00:10 AM 10/04/2013 01:20:52 AM NYPD \n",
"\n",
" Agency Name Complaint Type \\\n",
"0 New York City Police Department Noise - Street/Sidewalk \n",
"1 New York City Police Department Illegal Parking \n",
"2 New York City Police Department Noise - Commercial \n",
"3 New York City Police Department Noise - Vehicle \n",
"4 Department of Health and Mental Hygiene Rodent \n",
"... ... ... \n",
"111064 Department of Parks and Recreation Maintenance or Facility \n",
"111065 New York City Police Department Illegal Parking \n",
"111066 New York City Police Department Noise - Street/Sidewalk \n",
"111067 New York City Police Department Noise - Commercial \n",
"111068 New York City Police Department Blocked Driveway \n",
"\n",
" Descriptor Location Type Incident Zip \\\n",
"0 Loud Talking Street/Sidewalk 11432 \n",
"1 Commercial Overnight Parking Street/Sidewalk 11378 \n",
"2 Loud Music/Party Club/Bar/Restaurant 10032 \n",
"3 Car/Truck Horn Street/Sidewalk 10023 \n",
"4 Condition Attracting Rodents Vacant Lot 10027 \n",
"... ... ... ... \n",
"111064 Structure - Outdoors Park 11213 \n",
"111065 Posted Parking Sign Violation Street/Sidewalk 11434 \n",
"111066 Loud Talking Street/Sidewalk 10016 \n",
"111067 Loud Talking Club/Bar/Restaurant 11226 \n",
"111068 Partial Access Street/Sidewalk 11236 \n",
"\n",
" Incident Address ... Bridge Highway Direction Road Ramp \\\n",
"0 90-03 169 STREET ... NaN NaN \n",
"1 58 AVENUE ... NaN NaN \n",
"2 4060 BROADWAY ... NaN NaN \n",
"3 WEST 72 STREET ... NaN NaN \n",
"4 WEST 124 STREET ... NaN NaN \n",
"... ... ... ... ... \n",
"111064 NaN ... NaN NaN \n",
"111065 NaN ... NaN NaN \n",
"111066 344 EAST 28 STREET ... NaN NaN \n",
"111067 1233 FLATBUSH AVENUE ... NaN NaN \n",
"111068 1259 EAST 94 STREET ... NaN NaN \n",
"\n",
" Bridge Highway Segment Garage Lot Name Ferry Direction \\\n",
"0 NaN NaN NaN \n",
"1 NaN NaN NaN \n",
"2 NaN NaN NaN \n",
"3 NaN NaN NaN \n",
"4 NaN NaN NaN \n",
"... ... ... ... \n",
"111064 NaN NaN NaN \n",
"111065 NaN NaN NaN \n",
"111066 NaN NaN NaN \n",
"111067 NaN NaN NaN \n",
"111068 NaN NaN NaN \n",
"\n",
" Ferry Terminal Name Latitude Longitude \\\n",
"0 NaN 40.708275 -73.791604 \n",
"1 NaN 40.721041 -73.909453 \n",
"2 NaN 40.843330 -73.939144 \n",
"3 NaN 40.778009 -73.980213 \n",
"4 NaN 40.807691 -73.947387 \n",
"... ... ... ... \n",
"111064 NaN NaN NaN \n",
"111065 NaN 40.656160 -73.767353 \n",
"111066 NaN 40.740295 -73.976952 \n",
"111067 NaN 40.640182 -73.955306 \n",
"111068 NaN 40.640024 -73.900717 \n",
"\n",
" Location diff \n",
"0 (40.70827532593202, -73.79160395779721) -33.083329 \n",
"1 (40.721040535628305, -73.90945306791765) -33.188413 \n",
"2 (40.84332975466513, -73.93914371913482) -33.095814 \n",
"3 (40.7780087446372, -73.98021349023975) -33.202205 \n",
"4 (40.80769092704951, -73.94738703491433) -33.139696 \n",
"... ... ... \n",
"111064 NaN NaN \n",
"111065 (40.656160351546845, -73.76735262738222) -33.111192 \n",
"111066 (40.740295354643706, -73.97695165980414) -33.236656 \n",
"111067 (40.64018174662485, -73.95530566958138) -33.315124 \n",
"111068 (40.640024057399216, -73.90071711703163) -33.260693 \n",
"\n",
"[111069 rows x 53 columns]"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['diff'] = df['Longitude'] + df['Latitude']\n",
"\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"16. Zlicz wartości dla kolumny 'Descriptor', dla której Agency jest\n",
"równe NYPD."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df['Descriptor'].eq('NYPD').value_counts()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}