Table of Contents


In [1]:
import pandas as pd
import numpy as np

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams["figure.figsize"] = (15,7)

In [3]:
# This will give us an error!
data = pd.read_csv('Data/nyc/rest-insp.csv', sep=',')


---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-79b528678808> in <module>()
      1 # This will give us an error!
----> 2 data = pd.read_csv('Data/nyc/rest-insp.csv', sep=',')

/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
    644                     skip_blank_lines=skip_blank_lines)
    645 
--> 646         return _read(filepath_or_buffer, kwds)
    647 
    648     parser_f.__name__ = name

/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    399         return parser
    400 
--> 401     data = parser.read()
    402     parser.close()
    403     return data

/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py in read(self, nrows)
    937                 raise ValueError('skipfooter not supported for iteration')
    938 
--> 939         ret = self._engine.read(nrows)
    940 
    941         if self.options.get('as_recarray'):

/usr/local/lib/python3.6/site-packages/pandas/io/parsers.py in read(self, nrows)
   1506     def read(self, nrows=None):
   1507         try:
-> 1508             data = self._reader.read(nrows)
   1509         except StopIteration:
   1510             if self._first_chunk:

pandas/parser.pyx in pandas.parser.TextReader.read (pandas/parser.c:10415)()

pandas/parser.pyx in pandas.parser.TextReader._read_low_memory (pandas/parser.c:10691)()

pandas/parser.pyx in pandas.parser.TextReader._read_rows (pandas/parser.c:11728)()

pandas/parser.pyx in pandas.parser.TextReader._convert_column_data (pandas/parser.c:13162)()

pandas/parser.pyx in pandas.parser.TextReader._convert_tokens (pandas/parser.c:14116)()

pandas/parser.pyx in pandas.parser.TextReader._convert_with_dtype (pandas/parser.c:16172)()

pandas/parser.pyx in pandas.parser.TextReader._string_convert (pandas/parser.c:16400)()

pandas/parser.pyx in pandas.parser._string_box_utf8 (pandas/parser.c:22072)()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 3: invalid continuation byte

In [4]:
data = pd.read_csv('Data/nyc/rest-insp.csv', sep=',', encoding='latin1', index_col='Index', parse_dates=['INSPECTION DATE'], dayfirst=False)


/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2717: DtypeWarning: Columns (7) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)

In [5]:
data.head(5)


Out[5]:
CAMIS DBA BORO BUILDING STREET ZIPCODE PHONE CUISINE DESCRIPTION INSPECTION DATE ACTION VIOLATION CODE VIOLATION DESCRIPTION CRITICAL FLAG SCORE GRADE GRADE DATE RECORD DATE INSPECTION TYPE
Index
1 30075445 MORRIS PARK BAKE SHOP BRONX 1007 MORRIS PARK AVE 10462.0 7188924968 Bakery 2015-02-09 Violations were cited in the following area(s). 06C Food not protected from potential source of co... Critical 6.0 A 2/9/15 6/5/15 Cycle Inspection / Initial Inspection
2 30075445 MORRIS PARK BAKE SHOP BRONX 1007 MORRIS PARK AVE 10462.0 7188924968 Bakery 2014-03-03 Violations were cited in the following area(s). 10F Non-food contact surface improperly constructe... Not Critical 2.0 A 3/3/14 6/5/15 Cycle Inspection / Initial Inspection
3 30075445 MORRIS PARK BAKE SHOP BRONX 1007 MORRIS PARK AVE 10462.0 7188924968 Bakery 2013-10-10 No violations were recorded at the time of thi... NaN NaN Not Applicable NaN NaN NaN 6/5/15 Trans Fat / Second Compliance Inspection
4 30075445 MORRIS PARK BAKE SHOP BRONX 1007 MORRIS PARK AVE 10462.0 7188924968 Bakery 2013-09-11 Violations were cited in the following area(s). 04L Evidence of mice or live mice present in facil... Critical 6.0 A 9/11/13 6/5/15 Cycle Inspection / Re-inspection
5 30075445 MORRIS PARK BAKE SHOP BRONX 1007 MORRIS PARK AVE 10462.0 7188924968 Bakery 2013-09-11 Violations were cited in the following area(s). 04N Filth flies or food/refuse/sewage-associated (... Critical 6.0 A 9/11/13 6/5/15 Cycle Inspection / Re-inspection

In [6]:
data.tail(5)


Out[6]:
CAMIS DBA BORO BUILDING STREET ZIPCODE PHONE CUISINE DESCRIPTION INSPECTION DATE ACTION VIOLATION CODE VIOLATION DESCRIPTION CRITICAL FLAG SCORE GRADE GRADE DATE RECORD DATE INSPECTION TYPE
Index
490051 50037394 NaN BROOKLYN 299 MALCOLM X BLVD 11233.0 9172800441 Other 1900-01-01 NaN NaN NaN Not Applicable NaN NaN NaN 6/5/15 NaN
490052 50037396 NaN BROOKLYN 439 MARCUS GARVEY BLVD 11216.0 9179478007 Other 1900-01-01 NaN NaN NaN Not Applicable NaN NaN NaN 6/5/15 NaN
490053 50037399 NaN MANHATTAN 515 9TH AVE 10018.0 NaN Other 1900-01-01 NaN NaN NaN Not Applicable NaN NaN NaN 6/5/15 NaN
490054 50037400 NaN BRONX 767 ASTOR AVE 10467.0 9292223888 Other 1900-01-01 NaN NaN NaN Not Applicable NaN NaN NaN 6/5/15 NaN
490055 50037402 NaN QUEENS 9502 101ST AVE 11416.0 9173651004 Other 1900-01-01 NaN NaN NaN Not Applicable NaN NaN NaN 6/5/15 NaN

In [7]:
data['VIOLATION DESCRIPTION']


Out[7]:
Index
1         Food not protected from potential source of co...
2         Non-food contact surface improperly constructe...
3                                                       NaN
4         Evidence of mice or live mice present in facil...
5         Filth flies or food/refuse/sewage-associated (...
6         Food worker does not use proper utensil to eli...
7         Evidence of mice or live mice present in facil...
8         Personal cleanliness inadequate. Outer garment...
9         Food not protected from potential source of co...
10        Facility not vermin proof. Harborage or condit...
11        Non-food contact surface improperly constructe...
12        The original nutritional fact labels and/or in...
13        Cold food item held above 41å¼ F (smoked fish ...
14        Non-food contact surface improperly constructe...
15                                                      NaN
16        Cold food item held above 41å¼ F (smoked fish ...
17        Evidence of mice or live mice present in facil...
18        Food not protected from potential source of co...
19        Facility not vermin proof. Harborage or condit...
20        Non-food contact surface improperly constructe...
21        The original nutritional fact labels and/or in...
22                                                      NaN
23        Food Protection Certificate not held by superv...
24        Plumbing not properly installed or maintained;...
25        Food not protected from potential source of co...
26        Non-food contact surface improperly constructe...
27        Raw, cooked or prepared food is adulterated, c...
28        Personal cleanliness inadequate. Outer garment...
29        Non-food contact surface improperly constructe...
30        Cold food item held above 41å¼ F (smoked fish ...
                                ...                        
490026                                                  NaN
490027                                                  NaN
490028                                                  NaN
490029                                                  NaN
490030                                                  NaN
490031                                                  NaN
490032                                                  NaN
490033                                                  NaN
490034                                                  NaN
490035                                                  NaN
490036                                                  NaN
490037                                                  NaN
490038                                                  NaN
490039                                                  NaN
490040                                                  NaN
490041                                                  NaN
490042                                                  NaN
490043                                                  NaN
490044                                                  NaN
490045                                                  NaN
490046                                                  NaN
490047                                                  NaN
490048                                                  NaN
490049                                                  NaN
490050                                                  NaN
490051                                                  NaN
490052                                                  NaN
490053                                                  NaN
490054                                                  NaN
490055                                                  NaN
Name: VIOLATION DESCRIPTION, dtype: object

In [8]:
data['VIOLATION DESCRIPTION'][:10]


Out[8]:
Index
1     Food not protected from potential source of co...
2     Non-food contact surface improperly constructe...
3                                                   NaN
4     Evidence of mice or live mice present in facil...
5     Filth flies or food/refuse/sewage-associated (...
6     Food worker does not use proper utensil to eli...
7     Evidence of mice or live mice present in facil...
8     Personal cleanliness inadequate. Outer garment...
9     Food not protected from potential source of co...
10    Facility not vermin proof. Harborage or condit...
Name: VIOLATION DESCRIPTION, dtype: object

In [9]:
data[['VIOLATION DESCRIPTION','BORO']]


Out[9]:
VIOLATION DESCRIPTION BORO
Index
1 Food not protected from potential source of co... BRONX
2 Non-food contact surface improperly constructe... BRONX
3 NaN BRONX
4 Evidence of mice or live mice present in facil... BRONX
5 Filth flies or food/refuse/sewage-associated (... BRONX
6 Food worker does not use proper utensil to eli... BRONX
7 Evidence of mice or live mice present in facil... BRONX
8 Personal cleanliness inadequate. Outer garment... BRONX
9 Food not protected from potential source of co... BRONX
10 Facility not vermin proof. Harborage or condit... BRONX
11 Non-food contact surface improperly constructe... BRONX
12 The original nutritional fact labels and/or in... BRONX
13 Cold food item held above 41å¼ F (smoked fish ... BRONX
14 Non-food contact surface improperly constructe... BRONX
15 NaN BRONX
16 Cold food item held above 41å¼ F (smoked fish ... BRONX
17 Evidence of mice or live mice present in facil... BRONX
18 Food not protected from potential source of co... BRONX
19 Facility not vermin proof. Harborage or condit... BRONX
20 Non-food contact surface improperly constructe... BRONX
21 The original nutritional fact labels and/or in... BRONX
22 NaN BRONX
23 Food Protection Certificate not held by superv... BROOKLYN
24 Plumbing not properly installed or maintained;... BROOKLYN
25 Food not protected from potential source of co... BROOKLYN
26 Non-food contact surface improperly constructe... BROOKLYN
27 Raw, cooked or prepared food is adulterated, c... BROOKLYN
28 Personal cleanliness inadequate. Outer garment... BROOKLYN
29 Non-food contact surface improperly constructe... BROOKLYN
30 Cold food item held above 41å¼ F (smoked fish ... BROOKLYN
... ... ...
490026 NaN MANHATTAN
490027 NaN BRONX
490028 NaN QUEENS
490029 NaN MANHATTAN
490030 NaN BROOKLYN
490031 NaN BROOKLYN
490032 NaN MANHATTAN
490033 NaN MANHATTAN
490034 NaN QUEENS
490035 NaN BROOKLYN
490036 NaN QUEENS
490037 NaN QUEENS
490038 NaN BROOKLYN
490039 NaN MANHATTAN
490040 NaN MANHATTAN
490041 NaN Missing
490042 NaN QUEENS
490043 NaN QUEENS
490044 NaN BRONX
490045 NaN BRONX
490046 NaN MANHATTAN
490047 NaN MANHATTAN
490048 NaN QUEENS
490049 NaN MANHATTAN
490050 NaN MANHATTAN
490051 NaN BROOKLYN
490052 NaN BROOKLYN
490053 NaN MANHATTAN
490054 NaN BRONX
490055 NaN QUEENS

490055 rows × 2 columns


In [10]:
data['VIOLATION DESCRIPTION'].value_counts()


Out[10]:
Non-food contact surface improperly constructed. Unacceptable material used. Non-food contact surface or equipment improperly maintained and/or not properly sealed, raised, spaced or movable to allow accessibility for cleaning on all sides, above and underneath the unit.                      65006
Facility not vermin proof. Harborage or conditions conducive to attracting vermin to the premises and/or allowing vermin to exist.                                                                                                                                                                   45978
Evidence of mice or live mice present in facility's food and/or non-food areas.                                                                                                                                                                                                                      35161
Food contact surface not properly washed, rinsed and sanitized after each use and following any activity when contamination may have occurred.                                                                                                                                                       29906
Cold food item held above 41å¼ F (smoked fish and reduced oxygen packaged foods above 38 å¼F) except during necessary preparation.                                                                                                                                                                   28185
Plumbing not properly installed or maintained; anti-siphonage or backflow prevention device not provided where required; equipment or floor not properly drained; sewage disposal system in disrepair or not functioning properly.                                                                   26799
Food not protected from potential source of contamination during storage, preparation, transportation, display or service.                                                                                                                                                                           24917
Filth flies or food/refuse/sewage-associated (FRSA) flies present in facilitys food and/or non-food areas. Filth flies include house flies, little house flies, blow flies, bottle flies and flesh flies. Food/refuse/sewage-associated flies include fruit flies, drain flies and Phorid flies.    19212
Hot food item not held at or above 140å¼ F.                                                                                                                                                                                                                                                          15943
Raw, cooked or prepared food is adulterated, contaminated, cross-contaminated, or not discarded in accordance with HACCP plan.                                                                                                                                                                       13497
Cold food item held above 41Ìâå¼ F (smoked fish and reduced oxygen packaged foods above 38 Ìâå¼F) except during necessary preparation.                                                                                                                                                               12985
Live roaches present in facility's food and/or non-food areas.                                                                                                                                                                                                                                       12982
Sanitized equipment or utensil, including in-use food dispensing utensil, improperly used or stored.                                                                                                                                                                                                 11630
Wiping cloths soiled or not stored in sanitizing solution.                                                                                                                                                                                                                                            9314
Personal cleanliness inadequate. Outer garment soiled with possible contaminant.  Effective hair restraint not worn in an area where food is prepared.                                                                                                                                                8873
Food Protection Certificate not held by supervisor of food operations.                                                                                                                                                                                                                                8591
Proper sanitization not provided for utensil ware washing operation.                                                                                                                                                                                                                                  7702
Hot food item not held at or above 140Ìâå¼ F.                                                                                                                                                                                                                                                         7418
Food contact surface not properly maintained.                                                                                                                                                                                                                                                         5996
Toilet facility not maintained and provided with toilet paper, waste receptacle and self-closing door.                                                                                                                                                                                                5756
Appropriately scaled metal stem-type thermometer or thermocouple not provided or used to evaluate temperatures of potentially hazardous foods during cooking, cooling, reheating and holding.                                                                                                         5575
Pesticide use not in accordance with label or applicable laws. Prohibited chemical used/stored. Open bait station used.                                                                                                                                                                               5489
The original nutritional fact labels and/or ingredient label for a cooking oil, shortening or margarine or food item sold in bulk, or acceptable manufacturers documentation not maintained on site.                                                                                                 5106
Hand washing facility not provided in or near food preparation area and toilet room. Hot and cold running water at adequate pressure to enable cleanliness of employees not provided at facility. Soap and an acceptable hand-drying device not provided.                                             4764
Mechanical or natural ventilation system not provided, improperly installed, in disrepair and/or fails to prevent excessive build-up of grease, heat, steam condensation vapors, odors, smoke, and fumes.                                                                                             4741
Smoke free workplace smoking policy inadequate, not posted, not provided to employees.                                                                                                                                                                                                                4465
Thawing procedures improper.                                                                                                                                                                                                                                                                          4374
Food worker does not use proper utensil to eliminate bare hand contact with food that will not receive adequate additional heat treatment.                                                                                                                                                            4361
Single service item reused, improperly stored, dispensed; not used when required.                                                                                                                                                                                                                     4007
Bulb not shielded or shatterproof, in areas where there is extreme heat, temperature changes, or where accidental contact may occur.                                                                                                                                                                  3987
                                                                                                                                                                                                                                                                                                     ...  
Food prepared from ingredients at ambient temperature not cooled to 41å¼ F or below within 4 hours.                                                                                                                                                                                                     42
Precooked potentially hazardous food from commercial food processing establishment that is supposed to be heated, but is not heated to 140å¼ F within 2 hours.                                                                                                                                          34
Document issued by the Board of Health, Commissioner or Department unlawfully reproduced or altered.                                                                                                                                                                                                    24
Caloric content range (minimum to maximum) not posted on menus and or menu boards for each flavor, variety and size of each menu item that is offered for sale in different flavors, varieties and sizes.                                                                                               23
Unprotected food re-served.                                                                                                                                                                                                                                                                             22
Notice of the Department of Board of Health mutilated, obstructed, or removed.                                                                                                                                                                                                                          22
Potable water supply inadequate. Water or ice not potable or from unapproved source.  Cross connection in potable water supply system observed.                                                                                                                                                         20
Raw food not properly washed prior to serving.                                                                                                                                                                                                                                                          20
Food not labeled in accordance with HACCP plan.                                                                                                                                                                                                                                                         20
Food prepared from ingredients at ambient temperature not cooled to 41Ìâå¼ F or below within 4 hours.                                                                                                                                                                                                   19
Records and logs not maintained to demonstrate that HACCP plan has been properly implemented.                                                                                                                                                                                                           14
Meat, fish or molluscan shellfish served raw or undercooked without prior notification to customer.                                                                                                                                                                                                     13
Food allergy information poster not posted in language understood by all food workers.                                                                                                                                                                                                                  13
Precooked potentially hazardous food from commercial food processing establishment that is supposed to be heated, but is not heated to 140Ìâå¼ F within 2 hours.                                                                                                                                        12
Specific caloric content or range thereof not posted on menus, menu boards or food tags for each menu item offered as a combination meal with multiple options that are listed as single items.                                                                                                         11
Whole frozen poultry or poultry breasts, other than a single portion, is being cooked frozen or partially thawed.                                                                                                                                                                                       11
Out-of package sale of tobacco products observed.                                                                                                                                                                                                                                                       10
Unprotected potentially hazardous food re-served.                                                                                                                                                                                                                                                       10
Manufacture of frozen dessert not authorized on Food Service Establishment permit.                                                                                                                                                                                                                       7
Refrigeration used to implement HACCP plan not equipped with an electronic system that continuously monitors time and temperature.                                                                                                                                                                       3
Work place smoking policy inadequate, not posted, not provided.                                                                                                                                                                                                                                          2
Garbage receptacles not provided or inadequate. Garbage storage area not properly constructed or maintained; grinder or compactor dirty.                                                                                                                                                                 2
Reduced oxygen packaged (ROP) foods not cooled by an approved method whereby the internal food temperature is reduced to 38å¼ F within two hours of cooking and if necessary further cooled to a temperature of 34å¼ F within six hours of reaching 38å¼ F.                                              2
Unpasteurized milk or milk product present.                                                                                                                                                                                                                                                              1
Food item spoiled, adulterated, contaminated or cross-contaminated.                                                                                                                                                                                                                                      1
Milk or milk product undated, improperly dated or expired.                                                                                                                                                                                                                                               1
Sign prohibiting sale of tobacco products to minors not conspicuously posted.                                                                                                                                                                                                                            1
Lighting inadequate. Bulb not shielded or shatterproof.                                                                                                                                                                                                                                                  1
Choking first aid poster not posted. Alcohol and Pregnancy warning sign, inspection report sign; not posted. CPR sign not posted, equipment (resuscitation masks, adult & pediatric, latex gloves) not provided.                                                                                         1
Immersion basket not provided, used or of incorrect size. Incorrect manual technique. Test kit and thermometer not provided or used. Improper drying practices.                                                                                                                                          1
Name: VIOLATION DESCRIPTION, dtype: int64

In [11]:
#plt.style.use('ggplot')
viol_counts = data['VIOLATION DESCRIPTION'].value_counts()
viol_counts[:10]
viol_plot = viol_counts[:10].plot(kind='bar')
viol_plot.set_ylabel('No. of Violations')
viol_plot.set_title('NYC Restaurant Inspections: Top 10 Violations')
viol_plot.set_xticklabels( ('Non-food contact surface improperly constructed','Facility not vermin proof','Evidence of mice or live mice','Food contact surface not properly sanitized after use','Cold food item held above 41F', 'Plumbing/sewage disposal system in disrepair','Food not protected from contamination','Sewage-associated (FRSA) flies present in facility','Hot food item not held at or above 140F','Food is adulterated, contaminated, cross-contaminated') )


Out[11]:
[<matplotlib.text.Text at 0x110085048>,
 <matplotlib.text.Text at 0x10f0176d8>,
 <matplotlib.text.Text at 0x110a522e8>,
 <matplotlib.text.Text at 0x10249f080>,
 <matplotlib.text.Text at 0x10249fb38>,
 <matplotlib.text.Text at 0x1024a3630>,
 <matplotlib.text.Text at 0x1024a7128>,
 <matplotlib.text.Text at 0x10f017dd8>,
 <matplotlib.text.Text at 0x1024a7668>,
 <matplotlib.text.Text at 0x1024a3668>]

In [12]:
viol_counts = data['VIOLATION DESCRIPTION'].value_counts()
viol_counts[:10]


Out[12]:
Non-food contact surface improperly constructed. Unacceptable material used. Non-food contact surface or equipment improperly maintained and/or not properly sealed, raised, spaced or movable to allow accessibility for cleaning on all sides, above and underneath the unit.                      65006
Facility not vermin proof. Harborage or conditions conducive to attracting vermin to the premises and/or allowing vermin to exist.                                                                                                                                                                   45978
Evidence of mice or live mice present in facility's food and/or non-food areas.                                                                                                                                                                                                                      35161
Food contact surface not properly washed, rinsed and sanitized after each use and following any activity when contamination may have occurred.                                                                                                                                                       29906
Cold food item held above 41å¼ F (smoked fish and reduced oxygen packaged foods above 38 å¼F) except during necessary preparation.                                                                                                                                                                   28185
Plumbing not properly installed or maintained; anti-siphonage or backflow prevention device not provided where required; equipment or floor not properly drained; sewage disposal system in disrepair or not functioning properly.                                                                   26799
Food not protected from potential source of contamination during storage, preparation, transportation, display or service.                                                                                                                                                                           24917
Filth flies or food/refuse/sewage-associated (FRSA) flies present in facilitys food and/or non-food areas. Filth flies include house flies, little house flies, blow flies, bottle flies and flesh flies. Food/refuse/sewage-associated flies include fruit flies, drain flies and Phorid flies.    19212
Hot food item not held at or above 140å¼ F.                                                                                                                                                                                                                                                          15943
Raw, cooked or prepared food is adulterated, contaminated, cross-contaminated, or not discarded in accordance with HACCP plan.                                                                                                                                                                       13497
Name: VIOLATION DESCRIPTION, dtype: int64

In [14]:
#data['VIOLATION DESCRIPTION']
boros = pd.pivot_table(data,index=['BORO'],values=['VIOLATION DESCRIPTION'], aggfunc='count').sort_values(['VIOLATION DESCRIPTION'], ascending=False)
boros


Out[14]:
VIOLATION DESCRIPTION
BORO
MANHATTAN 195684
BROOKLYN 114998
QUEENS 110837
BRONX 42822
STATEN ISLAND 15814
Missing 244

In [15]:
boros.head(5).plot(kind="bar")


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x110f30c18>

In [16]:
pd.pivot_table(data,index=['BORO'],values=['VIOLATION DESCRIPTION'], aggfunc='count').plot(kind="bar")


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x107f41588>

In [17]:
is_rats = data['VIOLATION DESCRIPTION'] == "Evidence of mice or live mice present in facility's food and/or non-food areas."

In [18]:
rat_complaints = data[is_rats]
rat_complaints['BORO'].value_counts()


Out[18]:
MANHATTAN        13258
BROOKLYN          9197
QUEENS            8351
BRONX             3447
STATEN ISLAND      896
Missing             12
Name: BORO, dtype: int64

In [19]:
rat_counts = rat_complaints['BORO'].value_counts()
rat_plot = rat_counts[:5].plot(kind='bar')
rat_plot.set_ylabel('No. of Violations')
rat_plot.set_title('"Evidence of Mice or Live Mice" Violations by Borough')


Out[19]:
<matplotlib.text.Text at 0x108ef8ac8>

In [20]:
data['INSPECTION TYPE'].value_counts()


Out[20]:
Cycle Inspection / Initial Inspection                          271413
Cycle Inspection / Re-inspection                               134485
Pre-permit (Operational) / Initial Inspection                   25118
Pre-permit (Operational) / Re-inspection                        12316
Administrative Miscellaneous / Initial Inspection               11139
Pre-permit (Non-operational) / Initial Inspection                4692
Cycle Inspection / Reopening Inspection                          4486
Smoke-Free Air Act / Initial Inspection                          4034
Trans Fat / Initial Inspection                                   3945
Administrative Miscellaneous / Re-inspection                     3728
Trans Fat / Re-inspection                                        2406
Cycle Inspection / Compliance Inspection                         2310
Smoke-Free Air Act / Re-inspection                               2064
Inter-Agency Task Force / Initial Inspection                     1426
Trans Fat / Compliance Inspection                                1351
Pre-permit (Operational) / Compliance Inspection                 1189
Pre-permit (Operational) / Reopening Inspection                   730
Trans Fat / Second Compliance Inspection                          631
Administrative Miscellaneous / Compliance Inspection              429
Pre-permit (Non-operational) / Re-inspection                      292
Smoke-Free Air Act / Compliance Inspection                        277
Calorie Posting / Initial Inspection                              256
Administrative Miscellaneous / Reopening Inspection               122
Cycle Inspection / Second Compliance Inspection                   114
Smoke-Free Air Act / Second Compliance Inspection                 109
Calorie Posting / Re-inspection                                   103
Calorie Posting / Compliance Inspection                            55
Pre-permit (Operational) / Second Compliance Inspection            50
Administrative Miscellaneous / Second Compliance Inspection        46
Calorie Posting / Second Compliance Inspection                     33
Pre-permit (Non-operational) / Compliance Inspection                8
Smoke-Free Air Act / Limited Inspection                             6
Inter-Agency Task Force / Re-inspection                             2
Name: INSPECTION TYPE, dtype: int64

In [21]:
data['INSPECTION TYPE'].value_counts().sort_values(ascending=True).plot(kind="barh")


Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x108a3a390>