Updated by steve on Tuesday, November 6, 2018
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.
To start, you'll want to create worker for Airbnb listings. Run the worker a few times and you'll get results looking like this:
Next, export your results in CSV format and save them to a convenient location on your computer, like your desktop. In this example, we'll save our results to
Now, we'll write a little Python code to begin our visualizations.
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:
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:
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['listing.lng']) latitudes = list(df['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['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['pricing_quote.rate.amount'])]
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: