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 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
# Import necessary packages
import pandas as pd
import numpy as npLoad different datasets
airbnb_price_df = pd.read_csv('data/airbnb_price.csv')
print(airbnb_price_df.head())airbnb_last_review_df = pd.read_csv('data/airbnb_last_review.tsv', delimiter='\t')
print(airbnb_last_review_df.head())excel_file_path = 'data/airbnb_room_type.xlsx'
data = pd.ExcelFile(excel_file_path)
print(data.sheet_names)airbnb_room_type_df = data.parse(0)
print(airbnb_room_type_df.head())Combine Datasets into one
merged_df = airbnb_price_df.merge(airbnb_last_review_df, on='listing_id', how='inner') \
.merge(airbnb_room_type_df, on='listing_id', how='inner')
print(merged_df.head())Inspect new merged data frame and data types
print(merged_df.info())We can see price is of data type object instead of float. Last review is also not date and room type should be categorical. Let us work on those points. Also there are a few missing values but they don't affect our case study so it is okay to keep them as they are.
merged_df['price'] = merged_df['price'].str.split().str[0].astype(int)
print(merged_df['price'])merged_df['last_review'] = pd.to_datetime(merged_df['last_review'])
print(merged_df.info())print(merged_df['last_review'])