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 np
import matplotlib.pyplot as plt
import seaborn as sns
# Begin coding here ...
# Use as many cells as you likeimport pandas as pd
# First step of the project is to load the three different files provided into pandas dataframe.
# The three different files will be read in identical, however a little bit different ways from each other
# Update the file paths to the correct locations where the files are stored
df_csv = pd.read_csv("data/airbnb_price.csv")
df_tsv = pd.read_csv("data/airbnb_last_review.tsv", delimiter="\t")
df_xls = pd.read_excel("data/airbnb_room_type.xlsx")df_tsv.head()# Ensure that the key column names are correct in both dataframes
print(df_csv.columns)
print(df_tsv.columns)
# Correct the column names if necessary
# Assuming the correct key column name in df_tsv is 'key_in_tsv'
df_main = pd.merge(df_csv, df_tsv)df_main.head()df_main=pd.merge(df_main, df_xls)
df_main.head()df_main["last_review_date"]=pd.to_datetime(df_main['last_review'],
format='%B %d %Y')df_main.head()#Earliest and most recent views
date_earliest=df_main["last_review_date"].min()
print(date_earliest)
date_latest=df_main["last_review_date"].max()
print(date_latest)#Listings of private rooms
df_main["room_type"]=df_main["room_type"].str.lower()
private_rooms_count=df_main[df_main["room_type"]== 'private room'].shape[0]
print("Number of Private Rooms:", private_rooms_count)#Average listing price upto two decimal place
df_main["price"] = df_main["price"].astype(str).str.replace(" dollars", "", regex=True).astype(int)
avg_list_price = round(df_main["price"].mean(), 2)
print(avg_list_price)
#Cobining of new variables into one Dataframe
review_dates=pd.DataFrame({"first_reviewed":[date_earliest],
"last_reviewed":[date_latest],
"nb_private_rooms":[private_rooms_count],
"avg_price":[avg_list_price]
})
review_dates.head()