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 ...
# Use as many cells as you like

#Loading files
df_price = pd.read_csv('data/airbnb_price.csv')
df_room_type = pd.read_excel('data/airbnb_room_type.xlsx')
df_last_review = pd.read_csv('data/airbnb_last_review.tsv', sep='\t')

#looking loaded data frame
print(df_price.head())
print(df_room_type.head())
print(df_last_review.head())
#merging all data frames
df_full_airbnb = pd.merge(df_price, df_room_type, on='listing_id', how='left')
df_full_airbnb = pd.merge(df_full_airbnb, df_last_review, on='listing_id', how='left')

df_full_airbnb.head()
#determining the earliest and most recent review dates
#Converting the column 'last_review' to datatime
df_full_airbnb['last_review'] = pd.to_datetime(df_full_airbnb['last_review'], infer_datetime_format=True)

earliest_review = min(df_full_airbnb['last_review'])
last_review = max(df_full_airbnb['last_review'])

print(earliest_review, last_review)
#Finding how many listings are private rooms

#cleaning the 'room_type' column
df_full_airbnb['room_type'] = df_full_airbnb['room_type'].str.lower()
print(df_full_airbnb['room_type'].unique())
#Subset private rooms and count

num_private_room = df_full_airbnb[df_full_airbnb['room_type'] == 'private room'].shape[0]

print(num_private_room)
#Finding average price of listings
#Cleaning data

df_full_airbnb['price'] = df_full_airbnb['price'].str.replace('dollars', '')
print(df_full_airbnb.head())

#Converting string data to float data

df_full_airbnb['price'] = df_full_airbnb['price'].astype('float')

#Computing the mean price
mean_price = df_full_airbnb['price'].mean()
mean_price = round(mean_price, 2)
print(mean_price)
#Creating a data frame of review datas
dict_data ={
    'first_reviewed':[earliest_review],
    'last_reviewed':[last_review],
    'nb_private_rooms':[num_private_room],
    'avg_price':[mean_price]
}

review_dates = pd.DataFrame(dict_data)
print(review_dates)