FB Pixel

๐ŸŒ Visualize Worldwide Airbnb Listings By steve


โš–๏ธ Disclaimer: This article may reference endpoints that are not part of official APIs endorsed by airbnb.com and were found while using airbnb.com's official website and/or mobile app. They are documented here for informational purposes, such as to cross reference with HAR Files after using airbnb.com's official website and/or mobile app in accordance with airbnb.com's Terms of Service. Stevesie has no affiliation with airbnb.com.

If you access any of these endpoints with Stevesie or any other tool outside of an official airbnb.com client, you must check airbnb.com's Terms of Service to ensure said access is not prohibited. If you are not sure whether or not your use of Stevesie or any other tool in a specific instance violates airbnb.com's Terms of Service or applicable law, you should consult with competent legal counsel before proceeding. Learn more here: Is Data Scraping Legal?

With so much Airbnb data available, it can be hard to get a grasp on the trends and demands in your area. Here, we’ll explore ways to visualize Airbnb listings using Python and popular visualization libraries.

Check out the Airbnb Listings endpoint, where you can retrieve structured data for listings around the world. You can enter a city or just use the default settings to get listings from all over the world. If you execute the endpoint, you’ll see an option to download the Expanded CSV results so we can use it in a visualization library:

Save the CSV somewhere handy, such as your desktop: ~/Desktop/airbnb_global.csv.

Now, we’ll write a little Python code to begin our visualizations.

Loading into Pandas

Let’s first load our CSV into a Pandas dataframe:

import os
import pandas as pd

df = pd.read_csv(os.path.expanduser('~/Desktop/airbnb_global.csv'))

Pandas will automatically infer the column types for you. You can check out the column names with:

df.columns.values

Mapping with Cartopy

We’ll use Cartopy to visualize our listings on a map. Let’s start by importing the core modules we’ll need

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

ax = plt.axes([0, 0, 1, 1], projection=ccrs.PlateCarree())
ax.add_feature(cfeature.OCEAN, zorder=0)
ax.coastlines()

This will generate a blank world map as follows:

World Map

This is cool, but where’s our Airbnb data? Let’s now reference back to our Pandas dataframe and begin plotting our points.

Let’s first get the latitude and longitutes for our Airbnb listings:

longitudes = list(df['explore_tabs.sections.listings.listing.lng'])
latitudes = list(df['explore_tabs.sections.listings.listing.lat'])

Next, let’s make each point on the map proportional in size to the number of reviews about the listing, e.g.:

radiuses = (df['explore_tabs.sections.listings.listing.reviews_count'] / 50.0) ** 2

Lastly, let’s color each datapoint by price - higher priced listings will be more red and lower priced will be less intense.

import matplotlib.cm as cm
colors = [cm.hot(x) for x in list(df['explore_tabs.sections.listings.pricing_quote.can_instant_book'])]

We can now combine it all together and generate a world map of our Airbnbs:

ax.scatter(
    longitudes,
    latitudes,
    c=colors,
    s=radiuses,
    zorder=2,
    alpha=0.5)

Now we’ll get a nice map of Airbnb listings like this:

Airbnb Listings on a Map

Posted by steve on Nov. 6, 2018, 1:04 a.m. ๐Ÿšฉ  Report