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
import seaborn as sns
import matplotlib.pyplot as plt

# Begin coding here ...
# Use as many cells as you like

Practice your skills in importing and cleaning data and data manipulation and report insights to a real estate start-up

# importing csv file of data/airbnb_price.csv
# Import necessary packages
import pandas as pd
import numpy as np
airbnb_price = pd.read_csv("data/airbnb_price.csv")
airbnb_price
# importing tsv file of data/airbnb_last_review.csv
# Import necessary packages
import pandas as pd
import numpy as np
airbnb_last_review = pd.read_csv("data/airbnb_last_review.tsv", sep='\t')
airbnb_last_review
# importing tsv file of data/airbnb_room_type.csv
# Import necessary packages
import pandas as pd
import numpy as np
airbnb_room_type = pd.read_excel("data/airbnb_room_type.xlsx")
airbnb_room_type.size
#merging the three dataset together
import pandas as pd
data = pd.merge(airbnb_room_type, airbnb_price, on="listing_id", how="left")
data = pd.merge(data, airbnb_last_review, on="listing_id", how="left")
data.shape
# Drop rows where 'description' or 'host_name' are null
data_cleaned = data.dropna(subset=['description', 'host_name'])

# Validate that there are no null values in 'description' and 'host_name'
data_cleaned.isnull().sum()
data = data_cleaned
data.head(10)
# Standardize the 'room_type' column to proper case
data['room_type'] = data['room_type'].str.title()

# Verify the changes
data.room_type.unique()
# validating the price column
data['price'] = data['price'].replace('dollars', '', regex=True).astype(float)
data['price'] = data['price'].replace('[\.,]', '', regex=True).astype(float)

# Validate the changes
data.price.count()
# Change the datatype of 'last_review' column to datetime
data['last_review'] = pd.to_datetime(data['last_review'], errors='coerce')

# Validate the changes
data.last_review.head()
# Ensure that the split operation results in exactly two columns
data[['City', 'Neighborhood']] = data['nbhood_full'].str.split(', ', n=1, expand=True)

data.head()

DESCRIPTIVE STATISTIVE

# Summary statistics for price
price_stats = data['price'].describe()
print(price_stats)
# price description

plt.figure(figsize=(10, 6))
sns.histplot(data['price'], bins=30, kde=True)
plt.title('Price Distribution')
plt.xlabel('Price')
plt.ylabel('Frequency')
plt.show()

plt.figure(figsize=(10, 6))
sns.boxplot(x=data['price'])
plt.title('Price Distribution')
plt.xlabel('Price')
plt.show()