You’re part of a group

Switch to your group space and start collaborating with your teammates.

You’re part of a group

Switch to your group space and start collaborating with your teammates.

Sign up
Arnab Mitra/

Project: Exploring Airbnb Market Trends


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
# We've loaded your first package for you! You can add as many cells as you need.
import numpy as np
import pandas as pd
# Begin coding here ...
# Loading the data...

reviews = pd.read_csv(filepath_or_buffer="data/airbnb_last_review.tsv", sep="\t", encoding="UTF-8")
prices = pd.read_csv(filepath_or_buffer="data/airbnb_price.csv", encoding="UTF-8")
room_types = pd.read_excel("data/airbnb_room_type.xlsx")
# Change the last_review columns of the reviews DataFrame to Datetime
reviews['last_review'] = pd.to_datetime(reviews['last_review'],  format='%B %d %Y')

# Merge the 3 datasets on listing_id
properties_inter = reviews.merge(right=prices, how='inner', on='listing_id')

# Merging Further
properties = properties_inter.merge(right=room_types, how='inner', on='listing_id')

# What are the dates of the earliest and most recent reviews? 
# Store these values as two separate variables with your preferred names.

latest_review = properties['last_review'].max()
oldest_review = properties['last_review'].min()
print("Most Recent Review:", latest_review)
print("Oldest Review:", oldest_review)
# How many of the listings are private rooms? Save this into any variable.
properties['room_type'] = properties['room_type'].str.upper()



private_room_count = properties[properties['room_type'] == 'PRIVATE ROOM']['room_type'].count()
print("Private Room Count:", private_room_count)
properties['price'] = properties['price'].str.replace('dollars', '').str.strip()
properties['price'] = properties['price'].astype('float')
average_price = properties['price'].mean().round(2)

print("Average Room Price: $", average_price)
# Combine the new variables into one DataFrame called review_dates with four columns in the following order: 
# first_reviewed, last_reviewed, nb_private_rooms, and avg_price. 
# The DataFrame should only contain one row of values.

summary_report = {"first_reviewed": [oldest_review],
                  "last_reviewed": [latest_review],
                  "nb_private_rooms": [private_room_count],
                  "avg_price": [average_price]}
review_dates = pd.DataFrame(summary_report)

  • AI Chat
  • Code