Skip to content
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
# Import necessary packages
import pandas as pd
import numpy as np

# Begin coding here ...
# Use as many cells as you like
air_bnb_price = pd.read_csv('data/airbnb_price.csv')
#air_bnb_price.head()
air_bnb_roomtype = pd.read_excel('data/airbnb_room_type.xlsx')
#air_bnb_roomtype.head()
air_bnb_lastreview = pd.read_csv('data/airbnb_last_review.tsv', sep='\t')
#air_bnb_lastreview.head()
merge_1 = pd.merge(air_bnb_price, air_bnb_roomtype, on='listing_id')
merged_df = pd.merge(merge_1, air_bnb_lastreview, on='listing_id')
#merged_df.head()
#merged_df.info()
merged_df['last_review'] = pd.to_datetime(merged_df['last_review'])
#merged_df.info()
#earliest review date
earliest_review = merged_df['last_review'].min()
print(earliest_review)
recent_review = merged_df['last_review'].max()
print(recent_review)
room_types = merged_df['room_type'].unique()
merged_df['room_type'] = merged_df['room_type'].str.lower()
merged_df['room_type'].value_counts()
private_rooms = merged_df.loc[merged_df['room_type'] == 'private room']
private_rooms_count = private_rooms.shape[0]
merged_df['price'] = merged_df['price'].str.replace('dollars', '')
merged_df['price'] = merged_df['price'].astype('int')
merged_df['price'].dtype
average_listing_price = merged_df['price'].mean().round(2)
average_listing_price
#merging all variables into a dataframe
review_dates = pd.DataFrame(
{'first_reviewed': [earliest_review], 'last_reviewed': [recent_review], 'nb_private_rooms': [private_rooms_count], 'avg_price': [average_listing_price]}
)
review_dates