Welcome to New York City, one of the most-visited cities in the world. There are many Airbnb listings in New York City to meet the high demand for temporary lodging for travelers, which can be anywhere between a few nights to many months. In this notebook, we will take a closer look at the New York Airbnb market by combining data from multiple file types like .csv, .tsv, and .xlsx.
Recall that CSV, TSV, and Excel files are three common formats for storing data. Three files containing data on 2019 Airbnb listings are available to you:
data/airbnb_price.csv
listing_id: unique identifier of listingprice: nightly listing price in USDnbhood_full: name of borough and neighborhood where listing is located
data/airbnb_room_type.xlsx This is an Excel file containing data on Airbnb listing descriptions and room types.
listing_id: unique identifier of listingdescription: listing descriptionroom_type: Airbnb has three types of rooms: shared rooms, private rooms, and entire homes/apartments
data/airbnb_last_review.tsv This is a TSV file containing data on Airbnb host names and review dates.
listing_id: unique identifier of listinghost_name: name of listing hostlast_review: date when the listing was last reviewed
Our goals are to convert untidy data into appropriate formats to analyze, and answer key questions including:
- What is the average price, per night, of an Airbnb listing in NYC?
- How does the average price of an Airbnb listing, per month, compare to the private rental market?
- How many adverts are for private rooms?
- How do Airbnb listing prices compare across the five NYC boroughs?
# We've loaded your first package for you! You can add as many cells as you need.
import numpy as np1.Importing the data
1 hidden cell
2.Cleaning the price column
Now that the data has been loaded, the first step is to calculate the average price per listing by room_type. You may have noticed that the price column in the prices DataFrame currently records each value as a string with the currency (dollars) following, i.e.,
1 hidden cell
# remove "dollars" from price column
prices['price']= prices['price'].str.replace(' dollars', '')
# convert data type to int using astype() or to_numeric()
prices["price"] = pd.to_numeric(prices["price"])3.Calculating average price
1 hidden cell
4.Comparing costs to the private rental market with price per month
You know how much a listing costs, on average, per night, but it would be useful to have a benchmark for comparison! According to Zumper, a 1 bedroom apartment in New York City costs, on average, $3,100 per month. Let's convert the per night prices of our listings into monthly costs, so we can compare to the private market.
Add a new column, price_per_month, to the prices DataFrame, assuming a year consists of 365 days.
Calculate the average price of the price_per_month column and store as a new variable, average_price_per_month, rounded to two decimal places. Calculate how much more, in dollars, the average cost of an Airbnb listing is versus the private market, and store it as difference, rounding your final answer to two decimal places.
1 hidden cell
5.Cleaning the room_type column
Unsurprisingly, using Airbnb appears to be substantially more expensive than the private rental market. We should, however, consider that these Airbnb listings include single private rooms or even rooms to share, as well as entire homes/apartments.
1 hidden cell
6. What timeframe are we working with?
It seems there is a fairly similar-sized market opportunity for both private rooms (45% of listings) and entire homes/apartments (52%) on the Airbnb platform in NYC.
Now let's turn our attention to the reviews DataFrame. The last_review column contains the date of the last review in the format of "Month Day Year" e.g., May 21 2019. We've been asked to find out the earliest and latest review dates in the DataFrame, and ensure the format allows this analysis to be easily conducted going forwards.