Department of Consumer Affairs Charges

[This article was first published on R – NYC Data Science Academy Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The Charges Data Set

The NYC Open Data project provides the Department of Consumer Affairs data from 2016-2017.  The Department of Consumer Affairs was started in 1969 with the goal to “ensure compliance with local consumer protection and licensing laws, and State and federal regulations.”  They oversee almost every industry in NYC.  This data set describes the charges brought against NYC businesses and through analysis, can reflect how the enforcement plays out in practical terms.

It contains 50, 000 rows, which includes location data, some categorical information such as borough and business category, but not too much numerical information.  This project had to rely heavily upon count of charges for the visualizations.  A lot of time was spent on parsing through the Charge descriptions which were challenging to categorize.

Here’s a sample of what the Charge descriptions looked like:


“NYC Admin Code § 20-708 – STORE DID NOT CONSPICUOUSLY DISPLAY THE TOTAL SELLING PRICE, AT POINT OF DISPLAY, FOR ITEM.”                                                              

“6 RCNY § 5-70(a) – NO PRICE LIST FOR SERVICES DISPLAYED”                                           

“6 RCNY § 5-70(a) – PRICE LIST NOT DISPLAYED CONSPICUOUSLY”                                           

I parsed the first part which describes the rule and is before the dash of the description, then counted the number of charges vs each categorical description.  I would have liked to generalize about what each rule was, and turn this into a category as well.  However, I realized that would skew the analysis since for some categories, it’s difficult to conclude what the general description might be.  I also tried to find a source about the rules which I could then cross reference, but only found this searchable document which is difficult to scrape data from.

Who are the stakeholders and what can we learn?

Are you an activist citizen who is concerned about what regulations your local businesses are required to follow?  Or perhaps a policy maker who is interested in the applicability of the current laws and rules that protect consumers?  Would it be surprising to discover that most of the charges fall under just a few categories?  That industries such as pharmacies and tobacco retailers get enforced more heavily?  Or that more charges were brought against boroughs which have stronger retail business climates?  In analyzing the data, I discovered these kinds of trends.



The App

More insights can be garnered by visiting the app and manipulating the parameters.  I chose a very simple design and intended that the parameters could be applied to multiple plot types which can then be viewed by navigating through the tabs.  I left it in the user’s control to decide how many “top” industries or charge types they were interested in analyzing.

I also provided a word cloud to highlight what the most dominant words in the text of the charge descriptions.  I used some R packages to remove the extraneous English words and additionally, I removed words like “near”, “required” and “upon” which don’t relay any meaning.

The Code

And now without further ado, please feel free to peruse my code.

View the code on Gist.

To leave a comment for the author, please follow the link and comment on their blog: R – NYC Data Science Academy Blog. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)