Craiglist New York Data Analysis and Scraping

Posted on Oct 21, 2019
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

This article will go through how one would scraped data from New York Craigslist .ย ย 

Craigslist is an advertisement website that people use to find jobs, housing, items for sale, services, music gigs, etc. The code used to scrape the data can be found onย GitHub.ย 


Getting the Data

To collect the data BeautifulSoup from bs4, which is a Python library that is used for pulling data from HTML files, was used. The type and length of each item was checked to see if it matched the number of posts per page, which is 120 on Craigslist. The code below shows this process:ย 

Using the find_all method, shown in the code above. The website was examined, and the tag of each post was found. From the screenshot below it's shown that the parent tag of each posts is <li class = "result-row">.

Using the screenshot above the, the attributes that were extracted for each post were:

  • Time Posted
  • Neighborhoods
  • Number of bedrooms
  • Square Feet
  • URL
  • Price

After running the Beautiful Soup code, a dataframe was created that listed the values.ย 

The code that was used to create the dataframe is shown below:

Data Analysis

The reason for this analysis was to see what factors into the pricing of Manhattan apartments, and to help people looking for apartments. The below plot shows the distributions of prices in Manhattan. From the plot most of the apartments fall in the $2000-$3000 price range. There also seems to be some outliers around the $9000-12000 range.ย 

Regression analysis was also done between the Square footage and the Price, to see if there was any correlation between the two variables. From the scatterplot below it seems there is a slight positive correlation. However there seems to be some outliers, so square footage might not be the most reliable factor in determining the price of an apartment.ย 

Soย  to determine if square footage was the best indicator for determining the price, a regression plot with the best fit line was plotted. From the below plot it seems that the fit of the line for the two variables is adequate.ย 


As stated before it seems the best fit line was adequate, and for a deeper look the correlation for the two variables was calculated.ย 

Correlation matrix for variables

It is not surprising that there is a slightly strong correlation between the number of bedrooms and square footage, since the more bedrooms there are the bigger the apartment should be.ย  However there doesn't seem to be a strong correlation between price and number of bedrooms, in fact it's pretty weak.ย 

Further analysis was done regarding the prices by neighborhood. The bar plot shows the average price per neighborhood, and the box plot gives a more in depth analysis, showing the price range for each neighborhood.ย 

Boxplot of Prices by Neighborhood
Barplot of Prices by Neighborhood


Out of all the neighborhoods Soho was shown to have the largest spread. However further research will need to be done to understand what's happening with Tribeca since it has no whiskers.ย  Harlem seems to have the lowest average price per apartment. This data can help provide insight for a person looking for a apartment in Manhattan.ย 

In the future, further data cleaning will be done, and more insight will be done into other variables. Also, further data scraping will be done with the other boroughs.ย 

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI