Q#45: NYC Complaints

Suppose you have the following dataset, which shows a subset of 311 service requests from NYC Open Data. Given the dataset, plot the most common complaint types across all boroughs.

TRY IT YOURSELF

ANSWER

This question tests your data science skills to quickly gather information from a large dataset in the form of a visual. To do this, we will use Python, specifically the Pandas library to gather the data, get a count of what we want and return a plot.

First, we can load the data using the Pandas library into a dataframe structure with pd.read_csv(<link>). Next, we can chain functions on our stored dataframe to obtain the counts of complaints across every borough, pick out the top 10, and plot it. To get the counts of complaints, we first index the column with df[‘Complaint Type’] then use the .value_counts() functions followed by .iloc[:10] to get just the top 10 complaints. Finally, we use the .plot() with the kind = ‘bar’ argument to plot our bar plot of the results.

import pandas as pddf = pd.read_csv('https://raw.githubusercontent.com/erood/interviewqs.com_code_snippets/master/Datasets/311-service-requests.csv')df['Complaint Type'].value_counts().iloc[:10].plot(kind = 'bar', title = 'Top Complaints Across Boroughs');

--

--

--

Data Science tutorial working through solutions to Data Science Interview Questions

Recommended from Medium

Pre-GSoC Experience @ mlpack

Neo4j & DGL — a seamless integration

COVID-19 Analysis Report for Israel Government

A DataLA Summer Academy Story at LADOT Transit

K-means Clustering and Its real use-case in the Security Domain

StatSocial Digital Tribes — Country Sunday Warriors

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abish Pius

Abish Pius

Data Science Professional who teaches with unflashy, simple to understand python code.

More from Medium

How Data Science apply in Canto-pop?

Is Jeopardy! the Ultimate Data Scientist Gameshow?

data_leakage_blog

How Lockdown changed my life