What sets the price of an Airbnb night in New York?¶
An exploratory analysis of the 48,895 Airbnb listings in New York City (2019). The goal is to understand what drives the asking price of a night, and to find the best value for a family that wants an entire home near the centre.
Data: New York City Airbnb Open Data, 2019 (Kaggle), from Inside Airbnb. One row per listing.
Contents
- First look at the data
- Questions
- Cleaning
- Feature engineering
- Univariate analysis
- Bivariate analysis
- Multivariate analysis
- Answers
- Conclusion and limitations
import sys
from pathlib import Path
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.io as pio
import charts as ch # the dashboard's charts: same colours, category orders and Plotly defaults here and in the app
try:
import kaleido # noqa: F401 (static PNG copies: GitHub shows them, the README uses them)
pio.renderers.default = "plotly_mimetype+png"
pio.renderers["png"].width = 900
HAS_PNG = True
except ImportError:
pio.renderers.default = "plotly_mimetype+notebook"
HAS_PNG = False
DATA, IMAGES = Path("../../data/airbnb"), Path("images")
IMAGES.mkdir(exist_ok=True)
TIMES_SQUARE = (40.7580, -73.9855) # (latitude, longitude)
BOROUGH_COLORS = dict(zip(ch.ORDERS["borough"], [ch.BLUE, ch.ORANGE, ch.GREEN, "#152B3C", ch.GRAY]))
PRICE_TICKS = {"tickvals": [10, 20, 50, 100, 200, 500, 1000], "tickprefix": "$"} # for log price axes
def titled(fig, text):
# the app puts the title on the card; here it goes on the figure
return fig.update_layout(title=text, margin_t=60)
def save(fig, name):
if HAS_PNG:
fig.write_image(IMAGES / name, width=1000, height=fig.layout.height or 500)
1. First look at the data¶
| Column | Meaning |
|---|---|
id, name |
the listing and the title its host wrote |
host_id, host_name |
the host |
neighbourhood_group |
the borough: Manhattan, Brooklyn, Queens, Bronx, Staten Island |
neighbourhood |
the neighbourhood inside the borough |
latitude, longitude |
where the listing is |
room_type |
entire home/apt, private room or shared room |
price |
asking price per night, USD |
minimum_nights |
the shortest stay the host accepts |
number_of_reviews, last_review, reviews_per_month |
review activity |
calculated_host_listings_count |
how many listings the host has in the file |
availability_365 |
days of the next year that can be booked |
raw = pd.read_csv(DATA / "AB_NYC_2019.csv")
print(raw.shape)
raw.info()
(48895, 16) <class 'pandas.core.frame.DataFrame'> RangeIndex: 48895 entries, 0 to 48894 Data columns (total 16 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 48895 non-null int64 1 name 48879 non-null object 2 host_id 48895 non-null int64 3 host_name 48874 non-null object 4 neighbourhood_group 48895 non-null object 5 neighbourhood 48895 non-null object 6 latitude 48895 non-null float64 7 longitude 48895 non-null float64 8 room_type 48895 non-null object 9 price 48895 non-null int64 10 minimum_nights 48895 non-null int64 11 number_of_reviews 48895 non-null int64 12 last_review 38843 non-null object 13 reviews_per_month 38843 non-null float64 14 calculated_host_listings_count 48895 non-null int64 15 availability_365 48895 non-null int64 dtypes: float64(3), int64(7), object(6) memory usage: 6.0+ MB
raw.describe().T.round(1)
| count | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|
| id | 48895.0 | 19017143.2 | 10983108.4 | 2539.0 | 9471945.0 | 19677284.0 | 29152178.5 | 36487245.0 |
| host_id | 48895.0 | 67620010.6 | 78610967.0 | 2438.0 | 7822033.0 | 30793816.0 | 107434423.0 | 274321313.0 |
| latitude | 48895.0 | 40.7 | 0.1 | 40.5 | 40.7 | 40.7 | 40.8 | 40.9 |
| longitude | 48895.0 | -74.0 | 0.0 | -74.2 | -74.0 | -74.0 | -73.9 | -73.7 |
| price | 48895.0 | 152.7 | 240.2 | 0.0 | 69.0 | 106.0 | 175.0 | 10000.0 |
| minimum_nights | 48895.0 | 7.0 | 20.5 | 1.0 | 1.0 | 3.0 | 5.0 | 1250.0 |
| number_of_reviews | 48895.0 | 23.3 | 44.6 | 0.0 | 1.0 | 5.0 | 24.0 | 629.0 |
| reviews_per_month | 38843.0 | 1.4 | 1.7 | 0.0 | 0.2 | 0.7 | 2.0 | 58.5 |
| calculated_host_listings_count | 48895.0 | 7.1 | 33.0 | 1.0 | 1.0 | 1.0 | 2.0 | 327.0 |
| availability_365 | 48895.0 | 112.8 | 131.6 | 0.0 | 0.0 | 45.0 | 227.0 | 365.0 |
print("duplicate rows:", raw.duplicated().sum())
print("hosts:", raw["host_id"].nunique(), "| neighbourhoods:", raw["neighbourhood"].nunique())
print("largest host:", raw["calculated_host_listings_count"].max(), "listings")
duplicate rows: 0 hosts: 37457 | neighbourhoods: 221 largest host: 327 listings
- One row is one listing.
last_reviewis stored as text and four columns have empty cells. priceruns from 0 to 10,000 dollars with a median of 106, andminimum_nightsreaches 1,250: some values can't be real stays.- 37,457 hosts for 48,895 listings: some hosts run many places (up to 327).
2. Questions¶
- Q1 What does a typical night cost?
- Q2 Where are the listings, and which borough is the most expensive?
- Q3 How much does the room type change the price?
- Q4 Which neighbourhoods are the most and the least expensive?
- Q5 Does the price drop with distance from the centre (Times Square)?
- Q6 Do listings with more reviews cost more?
- Q7 Who are the hosts: individuals or businesses?
- Q8 For a family: where is the best value for an entire home close to the centre?
The price is skewed, so groups are compared by their median.
counts = raw.isna().sum()
missing = pd.DataFrame({"missing": counts, "percent": (counts / len(raw) * 100).round(1)})[counts > 0]
missing
| missing | percent | |
|---|---|---|
| name | 16 | 0.0 |
| host_name | 21 | 0.0 |
| last_review | 10052 | 20.6 |
| reviews_per_month | 10052 | 20.6 |
holes = raw.sample(2000, random_state=1).isna().astype(int).reset_index(drop=True)
fig = px.imshow(holes, color_continuous_scale=["#EEF2F4", ch.BLUE], aspect="auto", height=420)
fig.update_layout(coloraxis_showscale=False).update_yaxes(showticklabels=False, title="2,000 random listings")
titled(fig, "Where are the holes? (dark = missing)")
last_review and reviews_per_month are empty in the same rows. Are those the listings without any review?
no_reviews = raw["number_of_reviews"] == 0
print(no_reviews.sum(), "listings without reviews;",
"missing exactly there:", (raw["last_review"].isna() == no_reviews).all())
10052 listings without reviews; missing exactly there: True
Yes: the 10,052 empty cells are listings with no reviews yet. Their reviews_per_month is 0; last_review stays empty because there is no date to fill.
df = raw.drop(columns="host_name") # personal data, not needed: host_id identifies the host
df["name"] = df["name"].fillna("No name")
df["reviews_per_month"] = df["reviews_per_month"].fillna(0)
df["last_review"] = pd.to_datetime(df["last_review"])
df = df.rename(columns={"neighbourhood_group": "borough", "calculated_host_listings_count": "host_listings"})
df["room_type"] = df["room_type"].replace({"Entire home/apt": "Entire home"})
df.isna().sum()[lambda s: s > 0]
last_review 10052 dtype: int64
Outliers¶
q1, q3 = df["price"].quantile([0.25, 0.75])
iqr_upper = q3 + 1.5 * (q3 - q1)
print(f"IQR upper limit: {iqr_upper:.0f} | above it: {(df['price'] > iqr_upper).sum()}")
print("price = 0:", (df["price"] == 0).sum(), "| above 1,000:", (df["price"] > 1000).sum(),
"| minimum stay above a year:", (df["minimum_nights"] > 365).sum())
df.sort_values("price", ascending=False)[["name", "borough", "room_type", "price"]].head(10)
IQR upper limit: 334 | above it: 2972 price = 0: 11 | above 1,000: 239 | minimum stay above a year: 14
| name | borough | room_type | price | |
|---|---|---|---|---|
| 29238 | 1-BR Lincoln Center | Manhattan | Entire home | 10000 |
| 9151 | Furnished room in Astoria apartment | Queens | Private room | 10000 |
| 17692 | Luxury 1 bedroom apt. -stunning Manhattan views | Brooklyn | Entire home | 10000 |
| 6530 | Spanish Harlem Apt | Manhattan | Entire home | 9999 |
| 40433 | 2br - The Heart of NYC: Manhattans Lower East ... | Manhattan | Entire home | 9999 |
| 12342 | Quiet, Clean, Lit @ LES & Chinatown | Manhattan | Private room | 9999 |
| 30268 | Beautiful/Spacious 1 bed luxury flat-TriBeCa/Soho | Manhattan | Entire home | 8500 |
| 4377 | Film Location | Brooklyn | Entire home | 8000 |
| 29662 | East 72nd Townhouse by (Hidden by Airbnb) | Manhattan | Entire home | 7703 |
| 42523 | 70' Luxury MotorYacht on the Hudson | Manhattan | Entire home | 7500 |
The IQR rule flags everything above 334 dollars (6% of the listings), but a 400-dollar flat in Manhattan is expensive, not wrong. The top of the list is different: a furnished room at 10,000 a night and several at 9,999 are placeholders. A domain rule fits better: remove free listings, prices above 1,000 dollars and minimum stays above a year.
before = len(df)
df = df[(df["price"] > 0) & (df["price"] <= 1000) & (df["minimum_nights"] <= 365)].copy()
print(f"removed {before - len(df)} rows ({(before - len(df)) / before:.1%}), {len(df):,} left")
removed 264 rows (0.5%), 48,631 left
| Finding | Decision | Why |
|---|---|---|
host_name |
dropped | personal, answers no question |
10,052 missing last_review / reviews_per_month |
reviews per month = 0, dates left empty | missing because there are no reviews |
16 missing name |
"No name" | free text |
| price 0 or above 1,000 (250 listings) | removed | placeholders, not real prices |
| minimum stay above a year (14) | removed | not a short-term rental |
| IQR price outliers (2,972) | kept | expensive is not wrong |
4. Feature engineering¶
The distance to Times Square comes from the coordinates with the haversine formula (the great-circle distance on a sphere). Distances and host sizes are also grouped into bands.
def haversine_km(lat1, lon1, lat2, lon2):
lat1, lon1, lat2, lon2 = map(np.radians, [lat1, lon1, lat2, lon2])
a = np.sin((lat2 - lat1) / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin((lon2 - lon1) / 2) ** 2
return 6371 * 2 * np.arcsin(np.sqrt(a))
df["distance_km"] = haversine_km(df["latitude"], df["longitude"], *TIMES_SQUARE)
df["distance_band"] = pd.cut(df["distance_km"], bins=[0, 2, 5, 10, 50], labels=["< 2 km", "2-5 km", "5-10 km", "10+ km"])
df["host_type"] = pd.cut(df["host_listings"], bins=[0, 1, 5, 1000], labels=["1 listing", "2-5 listings", "6+ listings"])
df.to_csv(DATA / "airbnb_cleaned.csv", index=False) # the dashboard reads this file
df["distance_band"].value_counts(normalize=True, sort=False).round(3)
distance_band < 2 km 0.115 2-5 km 0.233 5-10 km 0.448 10+ km 0.204 Name: proportion, dtype: float64
Only 11.5% of the listings are within 2 km of Times Square; most (45%) are 5–10 km out.
Charts that draw one mark per listing use a random sample of 5,000 listings (as the dashboard's map does), so the notebook stays light; every number is computed on all the listings.
sample = df.sample(5_000, random_state=1)
p = df["price"]
print(pd.Series({"median": p.median(), "mean": p.mean(), "q1": p.quantile(0.25), "q3": p.quantile(0.75),
"skew": p.skew()}).round(2))
titled(ch.price_histogram(df), "Price: a long right tail").show()
median 105.00 mean 141.31 q1 69.00 q3 175.00 skew 2.94 dtype: float64
ticks = [10, 20, 50, 100, 200, 500, 1000]
fig = px.histogram(x=np.log10(sample["price"]).round(3), nbins=50, labels={"x": "Price per night ($, log scale)"})
fig.update_xaxes(tickvals=np.log10(ticks), ticktext=[f"${t:,}" for t in ticks]).update_yaxes(title="Listings")
titled(fig, "On a log axis: almost a bell (5,000 random listings)")
A typical night costs 105 dollars (median), and half of the listings cost 69–175. The mean (141) is pulled up by the tail (skew 2.94).
Boroughs and room types¶
print(df["borough"].value_counts(normalize=True).round(3))
titled(ch.room_donut(df), "What kind of place?").show()
borough Manhattan 0.442 Brooklyn 0.412 Queens 0.116 Bronx 0.022 Staten Island 0.008 Name: proportion, dtype: float64
85% of the listings are in Manhattan (44%) and Brooklyn (41%). Entire homes (52%) and private rooms (46%) are almost equal; shared rooms are rare (2%).
The listings on a map¶
fig = px.scatter_map(sample, lat="latitude", lon="longitude", color="borough", opacity=0.5,
color_discrete_map=BOROUGH_COLORS, hover_name="name", hover_data=["room_type", "price"],
zoom=9.6, height=600, map_style="carto-positron")
fig.update_traces(marker_size=4)
fig.add_scattermap(lat=[TIMES_SQUARE[0]], lon=[TIMES_SQUARE[1]], mode="markers+text", text=["Times Square"],
textposition="middle left", marker={"size": 14, "color": "black"}, showlegend=False)
titled(fig, "The listings draw New York").update_layout(legend_title=None, legend_itemsizing="constant")
The listings are densest around Times Square, lower Manhattan and north Brooklyn, and thin out with distance.
Reviews, availability, minimum stay¶
pd.Series({
"% with no reviews": (df["number_of_reviews"] == 0).mean() * 100,
"% available 0 days": (df["availability_365"] == 0).mean() * 100,
"% minimum exactly 30 nights": (df["minimum_nights"] == 30).mean() * 100,
}).round(1)
% with no reviews 20.4 % available 0 days 35.9 % minimum exactly 30 nights 7.7 dtype: float64
20% of the listings have no reviews and 36% can't be booked at all (0 days available), so the active market is smaller than the file. A spike at exactly 30 nights (7.7%) points to monthly rentals.
borough_median = df.groupby("borough")["price"].median().sort_values(ascending=False)
fig = px.box(sample, x="borough", y="price", log_y=True, category_orders={"borough": list(borough_median.index)},
labels={"borough": "", "price": "Price per night ($, log scale)"})
titled(fig.update_yaxes(**PRICE_TICKS), "Price by borough").show()
borough_median
borough Manhattan 149.0 Brooklyn 90.0 Queens 75.0 Staten Island 75.0 Bronx 65.0 Name: price, dtype: float64
Manhattan (149 dollars) is 2.3× the Bronx (65), but the boxes overlap a lot: the borough is not the whole story.
Room type (Q3)¶
room_median = df.groupby("room_type")["price"].median()
fig = px.box(sample, x="room_type", y="price", color="room_type", log_y=True,
labels={"room_type": "", "price": "Price per night ($, log scale)"})
titled(fig.update_yaxes(**PRICE_TICKS), "Three price ranges").update_layout(showlegend=False).show()
room_median
room_type Entire home 160.0 Private room 70.0 Shared room 45.0 Name: price, dtype: float64
Entire home 160, private room 70, shared room 45: an entire home costs 2.3× a private room.
Neighbourhoods (Q4)¶
nbhd = (df.groupby("neighbourhood")
.agg(median_price=("price", "median"), listings=("price", "size"), borough=("borough", "first"))
.query("listings >= 30")
.sort_values("median_price"))
print(len(nbhd), "neighbourhoods with 30+ listings")
pd.concat([nbhd.tail(5)[::-1], nbhd.head(5)])
115 neighbourhoods with 30+ listings
| median_price | listings | borough | |
|---|---|---|---|
| neighbourhood | |||
| Tribeca | 282.0 | 165 | Manhattan |
| NoHo | 250.0 | 77 | Manhattan |
| Flatiron District | 223.0 | 76 | Manhattan |
| Midtown | 208.0 | 1525 | Manhattan |
| West Village | 200.0 | 754 | Manhattan |
| Corona | 40.0 | 64 | Queens |
| Woodhaven | 52.0 | 88 | Queens |
| Borough Park | 53.5 | 136 | Brooklyn |
| Parkchester | 55.0 | 39 | Bronx |
| Norwood | 58.0 | 31 | Bronx |
Among the 115 neighbourhoods with 30+ listings (a median of 3 listings isn't reliable), Tribeca (282) costs 7× Corona (40).
Distance to the centre (Q5)¶
print(df.groupby("distance_band", observed=True)["price"].median())
fig = titled(ch.price_map(df), "Price on the map (5,000 random listings, colour capped at $400)")
save(fig, "price_map.png")
fig
distance_band < 2 km 181.0 2-5 km 150.0 5-10 km 95.0 10+ km 75.0 Name: price, dtype: float64
The price drops step by step: 181 dollars under 2 km, 150 at 2–5 km, 95 at 5–10 km, 75 beyond. On the map the expensive area crosses the river into Brooklyn and Queens: price follows distance, not borough borders.
Reviews (Q6)¶
r_reviews = df["number_of_reviews"].corr(df["price"], method="spearman")
fig = px.scatter(sample, x="number_of_reviews", y="price", log_y=True, opacity=0.25,
labels={"number_of_reviews": "Number of reviews", "price": "Price per night ($, log scale)"})
titled(fig.update_traces(marker_size=4).update_yaxes(**PRICE_TICKS), f"Reviews and price (Spearman r = {r_reviews:.2f})")
No link (Spearman r = -0.05). The listings with hundreds of reviews are almost all under 300 dollars.
Hosts (Q7)¶
hosts = df.drop_duplicates("host_id")
pd.DataFrame({
"% of hosts": hosts["host_type"].value_counts(normalize=True, sort=False) * 100,
"% of listings": df["host_type"].value_counts(normalize=True, sort=False) * 100,
}).round(1)
| % of hosts | % of listings | |
|---|---|---|
| host_type | ||
| 1 listing | 86.2 | 66.1 |
| 2-5 listings | 12.9 | 24.2 |
| 6+ listings | 0.9 | 9.8 |
86% of the hosts have one listing, but under 1% (6+ listings) own about 10% of the listings: a small group runs it as a business.
titled(ch.borough_room_heatmap(df), "Median price: borough × room type")
The room type matters more: the order is the same in every borough, and a private room in Manhattan (90) is cheaper than an entire home anywhere (100+).
Distance × room type¶
dist_room = df.pivot_table(index="distance_band", columns="room_type", values="price", aggfunc="median",
observed=True)
lines = dist_room.reset_index().melt(id_vars="distance_band", var_name="room_type", value_name="price")
fig = px.line(lines, x="distance_band", y="price", color="room_type", markers=True,
labels={"distance_band": "Distance to Times Square", "price": "Median price ($)"})
fig = titled(fig, "Further from the centre, cheaper, for every room type").update_layout(legend_title=None)
save(fig, "distance_room.png")
fig.show()
dist_room
| room_type | Entire home | Private room | Shared room |
|---|---|---|---|
| distance_band | |||
| < 2 km | 205.0 | 119.0 | 75.0 |
| 2-5 km | 189.0 | 91.0 | 70.0 |
| 5-10 km | 150.0 | 65.0 | 40.0 |
| 10+ km | 115.0 | 55.0 | 35.0 |
The distance effect holds inside every room type: entire homes go from 205 to 115 dollars, private rooms from 119 to 55.
Is it Manhattan, or is it distance?¶
homes = df[df["room_type"] == "Entire home"]
stats = homes.pivot_table(index="borough", columns="distance_band", values="price", aggfunc=["median", "size"],
observed=False)
homes_table = stats["median"].where(stats["size"] >= 30) # hide cells with fewer than 30 listings
fig = px.imshow(homes_table, text_auto="$.0f", color_continuous_scale="Blues", aspect="auto",
labels={"x": "", "y": "", "color": "Median price"})
titled(fig.update_layout(coloraxis_showscale=False), "Entire homes: median price, borough × distance (30+ listings)")
Mostly distance: an entire home in Brooklyn 2–5 km from Times Square (175) costs more than one in Manhattan 5–10 km away (160). Manhattan is expensive mainly because most of it is close to the centre.
Best value for a family (Q8)¶
family_options = (homes[homes["distance_km"] <= 5]
.groupby(["borough", "distance_band"], observed=True)["price"]
.agg(["median", "count"])
.sort_values("median"))
family_options
| median | count | ||
|---|---|---|---|
| borough | distance_band | ||
| Queens | 2-5 km | 149.0 | 282 |
| Brooklyn | 2-5 km | 175.0 | 679 |
| Manhattan | 2-5 km | 190.0 | 6498 |
| < 2 km | 205.0 | 3764 |
fam = family_options.reset_index()
fam["option"] = fam["borough"] + ", " + fam["distance_band"].astype(str)
fig = px.bar(fam, x="median", y="option", orientation="h", text_auto="$.0f", hover_data=["count"],
labels={"median": "Median price per night ($)", "option": ""})
titled(fig.update_yaxes(autorange="reversed"), "Entire homes within 5 km of Times Square")
Within 5 km, an entire home in Queens 2–5 km from Times Square costs a median of 149 dollars (282 listings), about 40 less than Manhattan at the same distance (190).
8. Answers¶
| Answer | |
|---|---|
| Q1 | a typical night costs 105 dollars (median); half of the listings cost 69–175 |
| Q2 | 85% are in Manhattan and Brooklyn; Manhattan is the most expensive (149), the Bronx the cheapest (65) |
| Q3 | entire home 160, private room 70, shared room 45; the room type moves the price more than the borough |
| Q4 | Tribeca (282) to Corona (40) among neighbourhoods with 30+ listings: 7× |
| Q5 | yes: 181 under 2 km down to 75 beyond 10 km, for every room type |
| Q6 | no link with reviews (Spearman -0.05) |
| Q7 | 86% of hosts have one listing; under 1% (6+ listings) own about 10% of the listings |
| Q8 | an entire home in Queens 2–5 km from Times Square, 149 a night, vs 190 in Manhattan at the same distance |
9. Conclusion and limitations¶
Findings
- The room type sets the level: an entire home costs about 2.3× a private room, in every borough.
- Location means distance, not the borough's name: a Brooklyn home near the centre costs more than one in Harlem.
- Popularity doesn't set the price.
Limitations
- These are asking prices, not what guests paid, in a 2019 snapshot (before COVID and the 2023 New York rules on short stays).
- 36% of the listings can't be booked (0 days available).
- Prices above 1,000 dollars were removed, real luxury listings included.
- No size, bedrooms or ratings: an entire home can be a studio or a five-bedroom house.
Next steps
- Seasonal prices, from the Inside Airbnb calendar file.
- Which listings are actually booked, from booking data.
The cleaned table (data/airbnb/airbnb_cleaned.csv) feeds the interactive dashboard in this folder.