# * coding:utf-8_*_
# 作者 :XiangLin
# 创建时间 :09/02/2020 12:01
# 文件 :2-2_Selecting_data_and_analysis_part1.py
# IDE :PyCharm
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# Make the graphs a bit prettier, and bigger
# This is necessary to show lots of columns in pandas 0.12.
# Not necessary in pandas 0.13.
plt.style.use("bmh")
plt.rc('font', family='SimHei', size=13) #显示中文
pd.set_option('display.max_columns',1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth',1000)
2.1中的数据集有点小啦,咱们这里用一个大一点的数据集
complaints = pd.read_csv('311-service-requests.csv')
其实warning暂时可以不用管,一般是python版本的问题
2.1 瞄一眼数据
dataframe这种格式还是很神奇的,比如说,你要是直接把dataframe丢出去输出一下,它会告诉你最基本的信息。
比如有多少行多少列,有多少非空的值等等。
print(complaints)
输出:
Unique Key Created Date Closed Date Agency Agency Name Complaint Type Descriptor Location Type Incident Zip Incident Address Street Name Cross Street 1 Cross Street 2 Intersection Street 1 Intersection Street 2 Address Type City Landmark Facility Type Status Due Date Resolution Action Updated Date Community Board Borough X Coordinate (State Plane) Y Coordinate (State Plane) Park Facility Name Park Borough School Name School Number School Region School Code School Phone Number School Address School City School State School Zip School Not Found School or Citywide Complaint Vehicle Type Taxi Company Borough Taxi Pick Up Location Bridge Highway Name Bridge Highway Direction Road Ramp Bridge Highway Segment Garage Lot Name \
0 26589651 10/31/2013 02:08:41 AM NaN NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 11432 90-03 169 STREET 169 STREET 90 AVENUE 91 AVENUE NaN NaN ADDRESS JAMAICA NaN Precinct Assigned 10/31/2013 10:08:41 AM 10/31/2013 02:35:17 AM 12 QUEENS QUEENS 1042027.0 197389.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 26593698 10/31/2013 02:01:04 AM NaN NYPD New York City Police Department Illegal Parking Commercial Overnight Parking Street/Sidewalk 11378 58 AVENUE 58 AVENUE 58 PLACE 59 STREET NaN NaN BLOCKFACE MASPETH NaN Precinct Open 10/31/2013 10:01:04 AM NaN 05 QUEENS QUEENS 1009349.0 201984.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 26594139 10/31/2013 02:00:24 AM 10/31/2013 02:40:32 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10032 4060 BROADWAY BROADWAY WEST 171 STREET WEST 172 STREET NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/31/2013 10:00:24 AM 10/31/2013 02:39:42 AM 12 MANHATTAN MANHATTAN 1001088.0 246531.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 26595721 10/31/2013 01:56:23 AM 10/31/2013 02:21:48 AM NYPD New York City Police Department Noise - Vehicle Car/Truck Horn Street/Sidewalk 10023 WEST 72 STREET WEST 72 STREET COLUMBUS AVENUE AMSTERDAM AVENUE NaN NaN BLOCKFACE NEW YORK NaN Precinct Closed 10/31/2013 09:56:23 AM 10/31/2013 02:21:10 AM 07 MANHATTAN MANHATTAN 989730.0 222727.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 26590930 10/31/2013 01:53:44 AM NaN DOHMH Department of Health and Mental Hygiene Rodent Condition Attracting Rodents Vacant Lot 10027 WEST 124 STREET WEST 124 STREET LENOX AVENUE ADAM CLAYTON POWELL JR BOULEVARD NaN NaN BLOCKFACE NEW YORK NaN NaN Pending 11/30/2013 01:53:44 AM 10/31/2013 01:59:54 AM 10 MANHATTAN MANHATTAN 998815.0 233545.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 26592370 10/31/2013 01:46:52 AM NaN NYPD New York City Police Department Noise - Commercial Banging/Pounding Club/Bar/Restaurant 11372 37 AVENUE 37 AVENUE 84 STREET 85 STREET NaN NaN BLOCKFACE JACKSON HEIGHTS NaN Precinct Open 10/31/2013 09:46:52 AM NaN 03 QUEENS QUEENS 1016948.0 212540.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
6 26595682 10/31/2013 01:46:40 AM NaN NYPD New York City Police Department Blocked Driveway No Access Street/Sidewalk 11419 107-50 109 STREET 109 STREET 107 AVENUE 109 AVENUE NaN NaN ADDRESS SOUTH RICHMOND HILL NaN Precinct Assigned 10/31/2013 09:46:40 AM 10/31/2013 01:59:51 AM 10 QUEENS QUEENS 1030919.0 187622.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 26595195 10/31/2013 01:44:19 AM 10/31/2013 01:58:49 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11417 137-09 CROSSBAY BOULEVARD CROSSBAY BOULEVARD PITKIN AVENUE VAN WICKLEN ROAD NaN NaN ADDRESS OZONE PARK NaN Precinct Closed 10/31/2013 09:44:19 AM 10/31/2013 01:58:49 AM 10 QUEENS QUEENS 1027776.0 184076.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 26590540 10/31/2013 01:44:14 AM 10/31/2013 02:28:04 AM NYPD New York City Police Department Noise - Commercial Loud Talking Club/Bar/Restaurant 10011 258 WEST 15 STREET WEST 15 STREET 7 AVENUE 8 AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/31/2013 09:44:14 AM 10/31/2013 02:00:56 AM 04 MANHATTAN MANHATTAN 984031.0 208847.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
9 26594392 10/31/2013 01:34:41 AM 10/31/2013 02:23:51 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11225 835 NOSTRAND AVENUE NOSTRAND AVENUE UNION STREET PRESIDENT STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/31/2013 09:34:41 AM 10/31/2013 01:48:26 AM 09 BROOKLYN BROOKLYN 997941.0 182725.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
10 26595176 10/31/2013 01:25:12 AM NaN NYPD New York City Police Department Noise - House of Worship Loud Music/Party House of Worship 11218 3775 18 AVENUE 18 AVENUE EAST 9 STREET EAST 8 STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Open 10/31/2013 09:25:12 AM NaN 14 BROOKLYN BROOKLYN 992726.0 170399.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
11 26591982 10/31/2013 01:24:14 AM 10/31/2013 01:54:39 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10003 187 2 AVENUE 2 AVENUE EAST 11 STREET EAST 12 STREET NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/31/2013 09:24:14 AM 10/31/2013 01:54:39 AM 03 MANHATTAN MANHATTAN 988110.0 205533.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
12 26594169 10/31/2013 01:20:57 AM 10/31/2013 02:12:31 AM NYPD New York City Police Department Illegal Parking Double Parked Blocking Vehicle Street/Sidewalk 10029 65 EAST 99 STREET EAST 99 STREET MADISON AVENUE PARK AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/31/2013 09:20:57 AM 10/31/2013 01:42:05 AM 11 MANHATTAN MANHATTAN 997470.0 226725.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
13 26594391 10/31/2013 01:20:13 AM NaN NYPD New York City Police Department Noise - Vehicle Engine Idling Street/Sidewalk 10466 NaN NaN NaN NaN STRANG AVENUE AMUNDSON AVENUE INTERSECTION BRONX NaN Precinct Open 10/31/2013 09:20:13 AM NaN 12 BRONX BRONX 1029467.0 264124.0 Unspecified BRONX Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
14 26590917 10/31/2013 01:19:54 AM NaN DOHMH Department of Health and Mental Hygiene Rodent Rat Sighting 1-2 Family Mixed Use Building 11219 63 STREET 63 STREET 13 AVENUE 14 AVENUE NaN NaN BLOCKFACE BROOKLYN NaN NaN Pending 11/30/2013 01:19:54 AM 10/31/2013 01:29:26 AM 10 BROOKLYN BROOKLYN 984467.0 167519.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
15 26591458 10/31/2013 01:14:02 AM 10/31/2013 01:30:34 AM NYPD New York City Police Department Noise - House of Worship Loud Music/Party House of Worship 10025 NaN NaN NaN NaN WEST 99 STREET BROADWAY INTERSECTION NEW YORK NaN Precinct Closed 10/31/2013 09:14:02 AM 10/31/2013 01:30:34 AM 07 MANHATTAN MANHATTAN 992454.0 229500.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
16 26594086 10/31/2013 12:54:03 AM 10/31/2013 02:16:39 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Music/Party Street/Sidewalk 10310 173 CAMPBELL AVENUE CAMPBELL AVENUE HENDERSON AVENUE WINEGAR LANE NaN NaN ADDRESS STATEN ISLAND NaN Precinct Closed 10/31/2013 08:54:03 AM 10/31/2013 02:07:14 AM 01 STATEN ISLAND STATEN ISLAND 952013.0 171076.0 Unspecified STATEN ISLAND Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
17 26595117 10/31/2013 12:52:46 AM NaN NYPD New York City Police Department Illegal Parking Posted Parking Sign Violation Street/Sidewalk 11236 NaN NaN NaN NaN ROCKAWAY PARKWAY SKIDMORE AVENUE INTERSECTION BROOKLYN NaN Precinct Open 10/31/2013 08:52:46 AM NaN 18 BROOKLYN BROOKLYN 1015289.0 169710.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
18 26590389 10/31/2013 12:51:00 AM NaN DOT Department of Transportation Street Light Condition Street Light Out NaN NaN 226 42 ST E 42 ST E CHURCH AVE SNYDER AVE NaN NaN ADDRESS NaN NaN NaN Open NaN NaN Unspecified BROOKLYN BROOKLYN NaN NaN Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
19 26594210 10/31/2013 12:46:27 AM NaN NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10033 NaN NaN NaN NaN WEST 184 STREET BROADWAY INTERSECTION NEW YORK NaN Precinct Assigned 10/31/2013 08:46:27 AM 10/31/2013 01:32:41 AM 12 MANHATTAN MANHATTAN 1002294.0 249712.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
20 26592932 10/31/2013 12:43:47 AM 10/31/2013 12:56:20 AM NYPD New York City Police Department Noise - House of Worship Loud Music/Party House of Worship 11216 778 PARK PLACE PARK PLACE ROGERS AVENUE NOSTRAND AVENUE NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/31/2013 08:43:47 AM 10/31/2013 12:56:20 AM 08 BROOKLYN BROOKLYN 997608.0 184656.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
21 26594152 10/31/2013 12:41:17 AM 10/31/2013 01:04:37 AM NYPD New York City Police Department Noise - Commercial Banging/Pounding Store/Commercial 10016 155 E 34TH ST E 34TH ST NaN NaN NaN NaN LATLONG NEW YORK NaN Precinct Closed 10/31/2013 08:41:17 AM 10/31/2013 01:04:38 AM 06 MANHATTAN MANHATTAN 990133.0 211136.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
22 26589678 10/31/2013 12:39:55 AM NaN NYPD New York City Police Department Noise - Vehicle Car/Truck Music Street/Sidewalk 11419 NaN NaN NaN NaN 112 STREET ATLANTIC AVENUE INTERSECTION SOUTH RICHMOND HILL NaN Precinct Open 10/31/2013 08:39:55 AM NaN 09 QUEENS QUEENS 1030314.0 191578.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
23 26592304 10/31/2013 12:38:00 AM NaN NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11216 371 TOMPKINS AVENUE TOMPKINS AVENUE MADISON STREET PUTNAM AVENUE NaN NaN ADDRESS BROOKLYN NaN Precinct Assigned 10/31/2013 08:38:00 AM 10/31/2013 01:16:53 AM 03 BROOKLYN BROOKLYN 999720.0 188825.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
24 26591892 10/31/2013 12:37:16 AM NaN NYPD New York City Police Department Blocked Driveway Partial Access Street/Sidewalk 10305 1496 BAY STREET BAY STREET LYMAN AVENUE SCHOOL ROAD NaN NaN ADDRESS STATEN ISLAND NaN Precinct Assigned 10/31/2013 08:37:16 AM 10/31/2013 12:52:10 AM 01 STATEN ISLAND STATEN ISLAND 967283.0 160518.0 Unspecified STATEN ISLAND Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
25 26591573 10/31/2013 12:35:18 AM 10/31/2013 02:41:35 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10312 24 PRINCETON LANE PRINCETON LANE HAMPTON GREEN DEAD END NaN NaN ADDRESS STATEN ISLAND NaN Precinct Closed 10/31/2013 08:35:18 AM 10/31/2013 01:45:17 AM 03 STATEN ISLAND STATEN ISLAND 929577.0 140964.0 Unspecified STATEN ISLAND Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
26 26590509 10/31/2013 12:33:00 AM NaN DOT Department of Transportation Street Light Condition Street Light Out NaN NaN 38 ST E 38 ST E CHURCH AVE LINDEN BLVD NaN NaN BLOCKFACE NaN NaN NaN Open NaN NaN Unspecified BROOKLYN BROOKLYN NaN NaN Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
27 26591379 10/31/2013 12:32:44 AM NaN DOHMH Department of Health and Mental Hygiene Harboring Bees/Wasps Bees/Wasps - Not a beekeper 3+ Family Mixed Use Building 10025 501 WEST 110 STREET WEST 110 STREET AMSTERDAM AVENUE BROADWAY NaN NaN ADDRESS NEW YORK NaN NaN Open 11/30/2013 12:32:44 AM NaN 09 MANHATTAN MANHATTAN 994143.0 231888.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
28 26594085 10/31/2013 12:32:08 AM NaN NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10026 121 WEST 116 STREET WEST 116 STREET LENOX AVENUE 7 AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Assigned 10/31/2013 08:32:08 AM 10/31/2013 02:00:57 AM 10 MANHATTAN MANHATTAN 997947.0 231613.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
29 26589201 10/31/2013 12:32:00 AM NaN DOT Department of Transportation Street Light Condition Street Light Out NaN 10309 295 BAYVIEW AVENUE BAYVIEW AVENUE VAIL AVENUE BAYVIEW LANE NaN NaN ADDRESS STATEN ISLAND NaN NaN Open NaN NaN 03 STATEN ISLAND STATEN ISLAND 927687.0 127837.0 Unspecified STATEN ISLAND Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
111039 26428764 10/04/2013 12:17:03 AM 10/04/2013 12:38:37 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10022 249 EAST 53 STREET EAST 53 STREET 3 AVENUE 2 AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:17:03 AM 10/04/2013 12:38:37 AM 06 MANHATTAN MANHATTAN 993036.0 215164.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111040 26426166 10/04/2013 12:16:22 AM 10/04/2013 05:50:49 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Store/Commercial 10029 252 EAST 110 STREET EAST 110 STREET 3 AVENUE 2 AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:16:22 AM 10/04/2013 05:50:49 AM 11 MANHATTAN MANHATTAN 1000407.0 228425.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111041 26438565 10/04/2013 12:16:00 AM NaN DEP Department of Environmental Protection Noise Noise: Construction Before/After Hours (NM1) NaN 11231 480 VAN BRUNT STREET VAN BRUNT STREET REED STREET DEAD END NaN NaN ADDRESS BROOKLYN NaN NaN Open NaN NaN 06 BROOKLYN BROOKLYN 979657.0 184924.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111042 26428990 10/04/2013 12:15:52 AM 10/04/2013 12:44:52 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10014 733 WASHINGTON STREET WASHINGTON STREET BANK STREET BETHUNE STREET NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:15:52 AM 10/04/2013 12:44:52 AM 02 MANHATTAN MANHATTAN 981950.0 207532.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111043 26432659 10/04/2013 12:15:46 AM 10/04/2013 04:18:45 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11218 1213 CORTELYOU ROAD CORTELYOU ROAD EAST 12 STREET EAST 13 STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:15:46 AM 10/04/2013 04:18:45 AM 14 BROOKLYN BROOKLYN 993451.0 172498.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111044 26426096 10/04/2013 12:14:09 AM 10/04/2013 01:03:46 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10032 539 WEST 162 STREET WEST 162 STREET ST NICHOLAS AVENUE BROADWAY NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:14:09 AM 10/04/2013 01:03:46 AM 12 MANHATTAN MANHATTAN 1000571.0 244054.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111045 26437764 10/04/2013 12:14:00 AM 10/04/2013 12:14:00 AM DEP Department of Environmental Protection Water System Dirty Water (WE) NaN 10022 251 EAST 51 STREET EAST 51 STREET 3 AVENUE 2 AVENUE NaN NaN ADDRESS NEW YORK NaN NaN Closed NaN 10/04/2013 12:14:00 AM 06 MANHATTAN MANHATTAN 992791.0 214702.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111046 26436286 10/04/2013 12:14:00 AM NaN DEP Department of Environmental Protection Noise Noise: Construction Before/After Hours (NM1) NaN 11231 480 VAN BRUNT STREET VAN BRUNT STREET REED STREET DEAD END NaN NaN ADDRESS BROOKLYN NaN NaN Open NaN NaN 06 BROOKLYN BROOKLYN 979657.0 184924.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111047 26428989 10/04/2013 12:13:08 AM 10/04/2013 02:12:47 AM NYPD New York City Police Department Illegal Parking Posted Parking Sign Violation Street/Sidewalk 11434 NaN NaN NaN NaN GUY R BREWER BOULEVARD ROCKAWAY BOULEVARD INTERSECTION JAMAICA NaN Precinct Closed 10/04/2013 08:13:08 AM 10/04/2013 02:12:47 AM 13 QUEENS QUEENS 1048801.0 178419.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111048 26430030 10/04/2013 12:12:07 AM 10/04/2013 02:45:24 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10027 215 WEST 131ST STREET WEST 131ST STREET NaN NaN NaN NaN LATLONG NEW YORK NaN Precinct Closed 10/04/2013 08:12:07 AM 10/04/2013 02:45:24 AM 01 MANHATTAN MANHATTAN 999107.0 235603.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111049 26429663 10/04/2013 12:12:07 AM 10/04/2013 01:03:44 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11209 8915 5 AVENUE 5 AVENUE 89 STREET 90 STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:12:07 AM 10/04/2013 01:03:44 AM 10 BROOKLYN BROOKLYN 976525.0 165015.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111050 26437763 10/04/2013 12:11:00 AM NaN DEP Department of Environmental Protection Noise Noise: Construction Before/After Hours (NM1) NaN 10028 NaN NaN NaN NaN EAST 84 STREET YORK AVENUE INTERSECTION NEW YORK NaN NaN Open NaN NaN 08 MANHATTAN MANHATTAN 998629.0 221493.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111051 26432955 10/04/2013 12:08:15 AM 10/04/2013 12:48:02 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10009 506 EAST 13 STREET EAST 13 STREET AVENUE A AVENUE B NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:08:15 AM 10/04/2013 12:48:03 AM 03 MANHATTAN MANHATTAN 989678.0 205065.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111052 26437035 10/04/2013 12:08:00 AM 10/04/2013 12:13:00 AM DEP Department of Environmental Protection Water System Dirty Water (WE) NaN 10022 325 EAST 54 STREET EAST 54 STREET 2 AVENUE 1 AVENUE NaN NaN ADDRESS NEW YORK NaN NaN Closed NaN 10/04/2013 12:13:00 AM 06 MANHATTAN MANHATTAN 993688.0 215099.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111053 26433197 10/04/2013 12:08:00 AM 10/04/2013 12:00:00 PM DSNY BCC - Queens East Derelict Vehicles 14 Derelict Vehicles Street 11413 220-11 145 AVENUE 145 AVENUE 221 STREET 221 STREET NaN NaN ADDRESS Springfield Gardens NaN DSNY Garage Pending NaN 10/04/2013 12:08:00 AM 13 QUEENS QUEENS 1051511.0 181411.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111054 26426060 10/04/2013 12:06:39 AM 10/04/2013 12:31:16 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 11224 4823 BEACH 48 STREET BEACH 48 STREET BODY OF WATER SURF AVENUE NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:06:39 AM 10/04/2013 12:31:16 AM 13 BROOKLYN BROOKLYN 980859.0 149681.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111055 26430628 10/04/2013 12:06:28 AM 10/04/2013 12:21:39 AM NYPD New York City Police Department Noise - Commercial Loud Talking Club/Bar/Restaurant 11209 7915 3 AVENUE 3 AVENUE 79 STREET 80 STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:06:28 AM 10/04/2013 12:21:39 AM 10 BROOKLYN BROOKLYN 976189.0 168214.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111056 26431648 10/04/2013 12:06:26 AM 10/23/2013 08:14:52 AM DOT Department of Transportation Street Sign - Missing Bus Stop Street 11378 NaN NaN NaN NaN 54 AVENUE 43 STREET INTERSECTION MASPETH NaN NaN Closed 10/14/2013 09:38:47 AM 10/23/2013 08:14:52 AM 02 QUEENS QUEENS 1005171.0 206064.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111057 26437034 10/04/2013 12:06:00 AM NaN DEP Department of Environmental Protection Noise Noise: Jack Hammering (NC2) NaN 10036 NaN NaN NaN NaN WEST 48 STREET BROADWAY INTERSECTION NEW YORK NaN NaN Open NaN NaN 05 MANHATTAN MANHATTAN 988451.0 216208.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111058 26426094 10/04/2013 12:05:12 AM 10/04/2013 01:08:29 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11237 211 KNICKERBOCKER AVENUE KNICKERBOCKER AVENUE JEFFERSON STREET TROUTMAN STREET NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:05:12 AM 10/04/2013 01:08:29 AM 04 BROOKLYN BROOKLYN 1004672.0 195540.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111059 26429040 10/04/2013 12:04:52 AM 10/04/2013 03:01:04 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10003 99 2 AVENUE 2 AVENUE EAST 5 STREET EAST 6 STREET NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:04:52 AM 10/04/2013 03:01:04 AM 03 MANHATTAN MANHATTAN 987393.0 204234.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111060 26434084 10/04/2013 12:04:00 AM NaN DEP Department of Environmental Protection Noise Noise: Construction Before/After Hours (NM1) NaN 10036 NaN NaN NaN NaN 8 AVENUE WEST 47 STREET INTERSECTION NEW YORK NaN NaN Open NaN NaN 04 MANHATTAN MANHATTAN 987720.0 216313.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111061 26426164 10/04/2013 12:03:00 AM 10/04/2013 02:14:57 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 11106 30-09 BROADWAY BROADWAY 30 STREET 31 STREET NaN NaN ADDRESS ASTORIA NaN Precinct Closed 10/04/2013 08:03:00 AM 10/04/2013 02:14:57 AM 01 QUEENS QUEENS 1004746.0 217004.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111062 26439710 10/04/2013 12:03:00 AM 10/04/2013 12:03:00 AM DEP Department of Environmental Protection Water System Dirty Water (WE) NaN 10022 325 EAST 54 STREET EAST 54 STREET 2 AVENUE 1 AVENUE NaN NaN ADDRESS NEW YORK NaN NaN Closed NaN 10/04/2013 12:03:00 AM 06 MANHATTAN MANHATTAN 993688.0 215099.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111063 26435569 10/04/2013 12:02:00 AM 10/04/2013 01:10:00 AM DEP Department of Environmental Protection Water System Dirty Water (WE) NaN 10022 311 EAST 50 STREET EAST 50 STREET 2 AVENUE 1 AVENUE NaN NaN ADDRESS NEW YORK NaN NaN Closed NaN 10/04/2013 01:10:00 AM 06 MANHATTAN MANHATTAN 993118.0 214222.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
111064 26426013 10/04/2013 12:01:13 AM 10/07/2013 04:07:16 PM DPR Department of Parks and Recreation Maintenance or Facility Structure - Outdoors Park 11213 NaN NaN NaN NaN NaN NaN NaN BROOKLYN NaN NaN Closed 10/18/2013 12:01:13 AM 10/07/2013 04:07:16 PM 08 BROOKLYN BROOKLYN NaN NaN Brower Park BROOKLYN Brower Park B012 NaN NaN 7189658900 Brooklyn, St. Marks, Kingston Avenues, Park Place BROOKLYN NY 11213 N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111065 26428083 10/04/2013 12:01:05 AM 10/04/2013 02:13:50 AM NYPD New York City Police Department Illegal Parking Posted Parking Sign Violation Street/Sidewalk 11434 NaN NaN NaN NaN GUY R BREWER BOULEVARD ROCKAWAY BOULEVARD INTERSECTION JAMAICA NaN Precinct Closed 10/04/2013 08:01:05 AM 10/04/2013 02:13:50 AM 13 QUEENS QUEENS 1048801.0 178419.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111066 26428987 10/04/2013 12:00:45 AM 10/04/2013 01:25:01 AM NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 10016 344 EAST 28 STREET EAST 28 STREET MOUNT CARMEL PLACE 1 AVENUE NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/04/2013 08:00:45 AM 10/04/2013 01:25:01 AM 06 MANHATTAN MANHATTAN 990637.0 208987.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111067 26426115 10/04/2013 12:00:28 AM 10/04/2013 04:17:32 AM NYPD New York City Police Department Noise - Commercial Loud Talking Club/Bar/Restaurant 11226 1233 FLATBUSH AVENUE FLATBUSH AVENUE AVENUE D NEWKIRK AVENUE NaN NaN ADDRESS BROOKLYN NaN Precinct Closed 10/04/2013 08:00:28 AM 10/04/2013 04:17:32 AM 14 BROOKLYN BROOKLYN 996654.0 172515.0 Unspecified BROOKLYN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN
111068 26428033 10/04/2013 12:00:10 AM 10/04/2013 01:20:52 AM NYPD New York City Police Department Blocked Driveway
2.2 选行或者列
上一节提到了,直接用名字就可以取。
print(complaints.columns)
print(complaints['Complaint Type'])
输出:
Index(['Unique Key', 'Created Date', 'Closed Date', 'Agency', 'Agency Name', 'Complaint Type', 'Descriptor', 'Location Type', 'Incident Zip', 'Incident Address', 'Street Name', 'Cross Street 1', 'Cross Street 2', 'Intersection Street 1', 'Intersection Street 2', 'Address Type', 'City', 'Landmark', 'Facility Type', 'Status', 'Due Date', 'Resolution Action Updated Date', 'Community Board', 'Borough', 'X Coordinate (State Plane)', 'Y Coordinate (State Plane)', 'Park Facility Name', 'Park Borough', 'School Name', 'School Number', 'School Region', 'School Code', 'School Phone Number', 'School Address', 'School City', 'School State', 'School Zip', 'School Not Found', 'School or Citywide Complaint', 'Vehicle Type', 'Taxi Company Borough', 'Taxi Pick Up Location', 'Bridge Highway Name', 'Bridge Highway Direction', 'Road Ramp', 'Bridge Highway Segment', 'Garage Lot Name', 'Ferry Direction', 'Ferry Terminal Name', 'Latitude', 'Longitude', 'Location'], dtype='object')
0 Noise - Street/Sidewalk
1 Illegal Parking
2 Noise - Commercial
3 Noise - Vehicle
4 Rodent
5 Noise - Commercial
6 Blocked Driveway
7 Noise - Commercial
8 Noise - Commercial
9 Noise - Commercial
10 Noise - House of Worship
11 Noise - Commercial
12 Illegal Parking
13 Noise - Vehicle
14 Rodent
15 Noise - House of Worship
16 Noise - Street/Sidewalk
17 Illegal Parking
18 Street Light Condition
19 Noise - Commercial
20 Noise - House of Worship
21 Noise - Commercial
22 Noise - Vehicle
23 Noise - Commercial
24 Blocked Driveway
25 Noise - Street/Sidewalk
26 Street Light Condition
27 Harboring Bees/Wasps
28 Noise - Street/Sidewalk
29 Street Light Condition
...
111039 Noise - Commercial
111040 Noise - Commercial
111041 Noise
111042 Noise - Street/Sidewalk
111043 Noise - Commercial
111044 Noise - Street/Sidewalk
111045 Water System
111046 Noise
111047 Illegal Parking
111048 Noise - Street/Sidewalk
111049 Noise - Commercial
111050 Noise
111051 Noise - Commercial
111052 Water System
111053 Derelict Vehicles
111054 Noise - Street/Sidewalk
111055 Noise - Commercial
111056 Street Sign - Missing
111057 Noise
111058 Noise - Commercial
111059 Noise - Street/Sidewalk
111060 Noise
111061 Noise - Commercial
111062 Water System
111063 Water System
111064 Maintenance or Facility
111065 Illegal Parking
111066 Noise - Street/Sidewalk
111067 Noise - Commercial
111068 Blocked Driveway
相信大家对python中list的切片操作非常熟悉,这里也一样,比如你要取前5条数据,直接用df[:5]即可。
拿前几条数据出来的原因是,我们可以先熟悉熟悉数据,为后期做分析热热身。
print(complaints[:5])
# 合并一下,取出某一列的前5行:
print(complaints['Complaint Type'][:5])
# 另外你先取列再切片 和 先切片再取列,其实是一样一样的。
print(complaints[:5]['Complaint Type'])
输出:
Unique Key Created Date Closed Date Agency Agency Name Complaint Type Descriptor Location Type Incident Zip Incident Address Street Name Cross Street 1 Cross Street 2 Intersection Street 1 Intersection Street 2 Address Type City Landmark Facility Type Status Due Date Resolution Action Updated Date Community Board Borough X Coordinate (State Plane) Y Coordinate (State Plane) Park Facility Name Park Borough School Name School Number School Region School Code School Phone Number School Address School City School State School Zip School Not Found School or Citywide Complaint Vehicle Type Taxi Company Borough Taxi Pick Up Location Bridge Highway Name Bridge Highway Direction Road Ramp Bridge Highway Segment Garage Lot Name Ferry Direction Ferry Terminal Name Latitude Longitude Location
0 26589651 10/31/2013 02:08:41 AM NaN NYPD New York City Police Department Noise - Street/Sidewalk Loud Talking Street/Sidewalk 11432 90-03 169 STREET 169 STREET 90 AVENUE 91 AVENUE NaN NaN ADDRESS JAMAICA NaN Precinct Assigned 10/31/2013 10:08:41 AM 10/31/2013 02:35:17 AM 12 QUEENS QUEENS 1042027.0 197389.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40.708275 -73.791604 (40.70827532593202, -73.79160395779721)
1 26593698 10/31/2013 02:01:04 AM NaN NYPD New York City Police Department Illegal Parking Commercial Overnight Parking Street/Sidewalk 11378 58 AVENUE 58 AVENUE 58 PLACE 59 STREET NaN NaN BLOCKFACE MASPETH NaN Precinct Open 10/31/2013 10:01:04 AM NaN 05 QUEENS QUEENS 1009349.0 201984.0 Unspecified QUEENS Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40.721041 -73.909453 (40.721040535628305, -73.90945306791765)
2 26594139 10/31/2013 02:00:24 AM 10/31/2013 02:40:32 AM NYPD New York City Police Department Noise - Commercial Loud Music/Party Club/Bar/Restaurant 10032 4060 BROADWAY BROADWAY WEST 171 STREET WEST 172 STREET NaN NaN ADDRESS NEW YORK NaN Precinct Closed 10/31/2013 10:00:24 AM 10/31/2013 02:39:42 AM 12 MANHATTAN MANHATTAN 1001088.0 246531.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40.843330 -73.939144 (40.84332975466513, -73.93914371913482)
3 26595721 10/31/2013 01:56:23 AM 10/31/2013 02:21:48 AM NYPD New York City Police Department Noise - Vehicle Car/Truck Horn Street/Sidewalk 10023 WEST 72 STREET WEST 72 STREET COLUMBUS AVENUE AMSTERDAM AVENUE NaN NaN BLOCKFACE NEW YORK NaN Precinct Closed 10/31/2013 09:56:23 AM 10/31/2013 02:21:10 AM 07 MANHATTAN MANHATTAN 989730.0 222727.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40.778009 -73.980213 (40.7780087446372, -73.98021349023975)
4 26590930 10/31/2013 01:53:44 AM NaN DOHMH Department of Health and Mental Hygiene Rodent Condition Attracting Rodents Vacant Lot 10027 WEST 124 STREET WEST 124 STREET LENOX AVENUE ADAM CLAYTON POWELL JR BOULEVARD NaN NaN BLOCKFACE NEW YORK NaN NaN Pending 11/30/2013 01:53:44 AM 10/31/2013 01:59:54 AM 10 MANHATTAN MANHATTAN 998815.0 233545.0 Unspecified MANHATTAN Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified N NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40.807691 -73.947387 (40.80769092704951, -73.94738703491433)
0 Noise - Street/Sidewalk
1 Illegal Parking
2 Noise - Commercial
3 Noise - Vehicle
4 Rodent
2.3 选多行
选一行是把这一行的名字告诉它,那选多行呢?恩,传一个名称list给他咯
print(complaints[['Complaint Type','Borough']])
# 好吧,再拼一下:多列的前n行。
print(complaints[['Complaint Type','Borough']][:10])
输出:
Complaint Type Borough
0 Noise - Street/Sidewalk QUEENS
1 Illegal Parking QUEENS
2 Noise - Commercial MANHATTAN
3 Noise - Vehicle MANHATTAN
4 Rodent MANHATTAN
5 Noise - Commercial QUEENS
6 Blocked Driveway QUEENS
7 Noise - Commercial QUEENS
8 Noise - Commercial MANHATTAN
9 Noise - Commercial BROOKLYN
10 Noise - House of Worship BROOKLYN
11 Noise - Commercial MANHATTAN
12 Illegal Parking MANHATTAN
13 Noise - Vehicle BRONX
14 Rodent BROOKLYN
15 Noise - House of Worship MANHATTAN
16 Noise - Street/Sidewalk STATEN ISLAND
17 Illegal Parking BROOKLYN
18 Street Light Condition BROOKLYN
19 Noise - Commercial MANHATTAN
20 Noise - House of Worship BROOKLYN
21 Noise - Commercial MANHATTAN
22 Noise - Vehicle QUEENS
23 Noise - Commercial BROOKLYN
24 Blocked Driveway STATEN ISLAND
25 Noise - Street/Sidewalk STATEN ISLAND
26 Street Light Condition BROOKLYN
27 Harboring Bees/Wasps MANHATTAN
28 Noise - Street/Sidewalk MANHATTAN
29 Street Light Condition STATEN ISLAND
... ... ...
111039 Noise - Commercial MANHATTAN
111040 Noise - Commercial MANHATTAN
111041 Noise BROOKLYN
111042 Noise - Street/Sidewalk MANHATTAN
111043 Noise - Commercial BROOKLYN
111044 Noise - Street/Sidewalk MANHATTAN
111045 Water System MANHATTAN
111046 Noise BROOKLYN
111047 Illegal Parking QUEENS
111048 Noise - Street/Sidewalk MANHATTAN
111049 Noise - Commercial BROOKLYN
111050 Noise MANHATTAN
111051 Noise - Commercial MANHATTAN
111052 Water System MANHATTAN
111053 Derelict Vehicles QUEENS
111054 Noise - Street/Sidewalk BROOKLYN
111055 Noise - Commercial BROOKLYN
111056 Street Sign - Missing QUEENS
111057 Noise MANHATTAN
111058 Noise - Commercial BROOKLYN
111059 Noise - Street/Sidewalk MANHATTAN
111060 Noise MANHATTAN
111061 Noise - Commercial QUEENS
111062 Water System MANHATTAN
111063 Water System MANHATTAN
111064 Maintenance or Facility BROOKLYN
111065 Illegal Parking QUEENS
111066 Noise - Street/Sidewalk MANHATTAN
111067 Noise - Commercial BROOKLYN
111068 Blocked Driveway BROOKLYN
[111069 rows x 2 columns]
Complaint Type Borough
0 Noise - Street/Sidewalk QUEENS
1 Illegal Parking QUEENS
2 Noise - Commercial MANHATTAN
3 Noise - Vehicle MANHATTAN
4 Rodent MANHATTAN
5 Noise - Commercial QUEENS
6 Blocked Driveway QUEENS
7 Noise - Commercial QUEENS
8 Noise - Commercial MANHATTAN
9 Noise - Commercial BROOKLYN
2.4 想统计找出Top类型的数据?
dataframe真的很智能,比如你告诉它,我要统计一下数量了!(用.value_counts()函数),那它就帮你统计数量了:
print(complaints['Complaint Type'].value_counts())
# 注意哈,咱们拿到的结果是排过序的,也就是说如果我只要top 10的话,其实截断一下就可以了:
complaints_counts = complaints['Complaint Type'].value_counts()
print(complaints_counts[:10])
HEATING 14200
GENERAL CONSTRUCTION 7471
Street Light Condition 7117
DOF Literature Request 5797
PLUMBING 5373
PAINT - PLASTER 5149
Blocked Driveway 4590
NONCONST 3998
Street Condition 3473
Illegal Parking 3343
Noise 3321
Traffic Signal Condition 3145
Dirty Conditions 2653
Water System 2636
Noise - Commercial 2578
ELECTRIC 2350
Broken Muni Meter 2070
Noise - Street/Sidewalk 1928
Sanitation Condition 1824
Rodent 1632
Sewer 1627
Taxi Complaint 1227
Consumer Complaint 1227
Damaged Tree 1180
Overgrown Tree/Branches 1083
Missed Collection (All Materials) 973
Graffiti 973
Building/Use 942
Root/Sewer/Sidewalk Condition 836
Derelict Vehicle 803
...
Miscellaneous Categories 5
Posting Advertisement 5
Fire Alarm - Modification 5
Poison Ivy 5
Internal Code 5
Illegal Animal Sold 4
Transportation Provider Complaint 4
Special Natural Area District (SNAD) 4
Ferry Complaint 4
Fire Alarm - Replacement 3
Invitation 3
Illegal Fireworks 3
Adopt-A-Basket 3
Window Guard 2
Opinion for the Mayor 2
DFTA Literature Request 2
Public Assembly 2
Legal Services Provider Complaint 2
Misc. Comments 2
DHS Income Savings Requirement 1
Tunnel Condition 1
DWD 1
Municipal Parking Facility 1
X-Ray Machine/Equipment 1
Ferry Permit 1
Highway Sign - Damaged 1
Snow 1
Stalled Sites 1
Trans Fat 1
Open Flame Permit 1
Name: Complaint Type, Length: 165, dtype: int64
HEATING 14200
GENERAL CONSTRUCTION 7471
Street Light Condition 7117
DOF Literature Request 5797
PLUMBING 5373
PAINT - PLASTER 5149
Blocked Driveway 4590
NONCONST 3998
Street Condition 3473
Illegal Parking 3343
Name: Complaint Type, dtype: int64
哈哈,聪明的你一定想到上一节说的绘图,是的,咱们可以把top10画出来。
complaints_counts[:10].plot(figsize=(20,6)) #默认是折线图
plt.show()
complaints_counts[:10].plot(kind='bar') # 柱状图
plt.show()
I love you because you are the last person I want to talk to before going to bed at night.
我爱你是因为你是我晚上睡睡前最后一个想说话的人。
—《飞屋环游记》
数据链接:链接:https://pan.baidu.com/s/1BX9z2WeAHrA0hduuf1OD0A
提取码:o2o8
来自七月在线数据挖掘算法
向林
2020年2月9日于重庆城口
好好学习,天天向上,终有所获