Skip to content

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 project, 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 This is a CSV file containing data on Airbnb listing prices and locations.

  • listing_id: unique identifier of listing
  • price: nightly listing price in USD
  • nbhood_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 listing
  • description: listing description
  • room_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 listing
  • host_name: name of listing host
  • last_review: date when the listing was last reviewed
# Import necessary packages
import pandas as pd
import numpy as np

# Begin coding here ...
airbnb_price = pd.read_csv('data/airbnb_price.csv')
airbnb_last_review = pd.read_csv('data/airbnb_last_review.tsv', sep='\t',
                                 parse_dates=['last_review'])
airbnb_room_type = pd.read_excel('data/airbnb_room_type.xlsx')
print(airbnb_price.head(), '\n',
    airbnb_last_review.head(), '\n',
    airbnb_room_type.head())
# Use as many cells as you like
# Merging the the 3 DataFrames
airbnb_merge = airbnb_price.merge(airbnb_last_review, on='listing_id')\
            .merge(airbnb_room_type, on='listing_id')
airbnb_merge.head()
# Subsetting for rows with the most latest and earliest reviews
last_review = airbnb_merge['last_review'].max()
first_review = airbnb_merge['last_review'].min()
print(first_review, last_review)
# Cleaning values in room_type with lower()
airbnb_merge['room_type'] = airbnb_merge['room_type'].str.lower()

# Finding how many rooms are listed as 'private room' 
nb_private_rooms = airbnb_merge['room_type'].value_counts().loc['private room']
nb_private_rooms
# Cleaning the price column and converting the data
avg_price = airbnb_merge['price'].str.replace(' dollars', '').astype(int)\
                    .mean().round(decimals=2) # Calculating the average price for room
avg_price
# Creating a dictionary with the first_reviewed, last_reviewed, nb_private_rooms, and avg_price
dict = {
    'first_reviewed' : [first_review],
    'last_reviewed' : [last_review],
    'nb_private_rooms' : [nb_private_rooms],
    'avg_price' : [avg_price]
}

# Create a dataframe using the dictionary
review_dates = pd.DataFrame(dict)
review_dates