In [1]:
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline

import matplotlib as mpl

In [2]:
listings = pd.read_csv('listings.csv')

In [3]:
listings.head()


Out[3]:
id name host_id host_name neighbourhood_group neighbourhood latitude longitude room_type price minimum_nights number_of_reviews last_review reviews_per_month calculated_host_listings_count availability_365
0 8207551 Room in Sant Antoni huge terrasse 7783989 Christophe Ciutat Vella el Raval 41.380844 2.163840 Private room 39 1 2 2015-09-27 0.11 2 0
1 14958299 Next To Las Ramblas, Unique, Wif1 48792562 Kristina Ciutat Vella el Raval 41.379712 2.164466 Entire home/apt 60 1 15 2017-02-09 2.26 1 99
2 7766152 Sunny whole flat in Raval/Ramblas 40843803 Maria Ciutat Vella el Raval 41.380963 2.165327 Entire home/apt 55 2 8 2015-11-16 0.40 1 151
3 9237132 Apartment in the heart of Barcelona 47842001 Vik Ciutat Vella el Raval 41.377780 2.165551 Entire home/apt 99 2 55 2017-03-19 3.17 1 303
4 1406827 Centric Bohemian next Ramblas&Macba 7573380 Croki Ciutat Vella el Raval 41.380838 2.164575 Entire home/apt 45 2 226 2017-03-28 5.06 1 26

In [4]:
len(listings)


Out[4]:
17653

In [5]:
fig,ax = plt.subplots(figsize=(10,10))
ax.scatter(listings.longitude,listings.latitude, marker='+', s=3, alpha=0.4, c='k')


Out[5]:
<matplotlib.collections.PathCollection at 0x7f69e182bf10>

In [6]:
fig,ax = plt.subplots(figsize=(10,10))
ax.hexbin(listings.longitude,listings.latitude,gridsize=100,cmap='viridis')


Out[6]:
<matplotlib.collections.PolyCollection at 0x7f69c6c58ad0>

In [13]:
listings["circle_size"] = ((listings.price-listings.price.min())/(listings.price.max()-listings.price.min())*100)*2

#listings.circle_size.hist(bins=50)
listings[["circle_size","price"]].hist(bins=50,figsize=(10,5))
plt.show()



In [14]:
ls_oly_pz = listings[listings.price-listings.price.mean()< (2*listings.price.std())]

In [15]:
ls_oly_pz[["circle_size","price"]].hist(bins=50,figsize=(10,5))


Out[15]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f69b189b810>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f69b2ef0410>]], dtype=object)

In [16]:
from bokeh.io import output_file, show
from bokeh.models import (
    GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool, 
    WheelZoomTool, BoxZoomTool, ResetTool, HoverTool
)

map_options = GMapOptions(lat=41.38, lng=2.16, map_type="roadmap", zoom=13)

plot = GMapPlot(
    x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, webgl=True
)
plot.title.text = "airbnb Barcelona"

# For GMaps to function, Google requires you obtain and enable an API key:
#
#     https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
plot.api_key = "AIzaSyAQXBn6zdairzB6G1x_HDDTK1t4A6DyTyc"

source = ColumnDataSource(ls_oly_pz)


hover = HoverTool(tooltips = [('Barri', '@neighbourhood'),('preu','@price')])

circle = Circle(x="longitude", y="latitude", size="circle_size", fill_color="blue", fill_alpha=0.8, line_color=None)
plot.add_glyph(source, circle)

plot.add_tools(PanTool(), WheelZoomTool(), ResetTool(), BoxZoomTool(), hover)
output_file("gmap_plot.html")
show(plot)

In [67]:
ls_oly_pz.price.hist(bins=60)


Out[67]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fe56f6b95d0>

In [100]:
sns.distplot(ls_oly_pz.price[ls_oly_pz.neighbourhood == 'Ciutat Vella'], hist=False, label="Ciutat vella")
sns.distplot(ls_oly_pz.price[ls_oly_pz.neighbourhood == 'Sarri\xc3\xa0-Sant Gervasi'], hist=False, label="corts")
plt.legend()


Out[100]:
<matplotlib.legend.Legend at 0x7fe57cfea890>

In [107]:
sns.distplot(ls_oly_pz.price[ls_oly_pz.neighbourhood == 'Sant Pere, Santa Caterina i la Ribera'
                            ], hist=False, label="born")
sns.distplot(ls_oly_pz.price[ls_oly_pz.neighbourhood == 'el Clot'], hist=False, label="clot")
plt.legend()


Out[107]:
<matplotlib.legend.Legend at 0x7fe56888d790>

In [101]:
print ([x for x in ls_oly_pz.neighbourhood.unique()])


['el Raval', 'el Barri G\xc3\xb2tic', "la Dreta de l'Eixample", "l'Antiga Esquerra de l'Eixample", "la Nova Esquerra de l'Eixample", 'la Barceloneta', 'Sant Pere, Santa Caterina i la Ribera', 'el Fort Pienc', 'la Sagrada Fam\xc3\xadlia', 'Sant Antoni', 'el Poble Sec', 'la Marina de Port', 'el Clot', 'la Marina del Prat Vermell', 'la Font de la Guatlla', 'Hostafrancs', 'la Bordeta', 'Sants - Badal', 'Sants', 'les Corts', 'la Maternitat i Sant Ramon', 'el Baix Guinard\xc3\xb3', 'Pedralbes', 'Vallvidrera, el Tibidabo i les Planes', 'Sarri\xc3\xa0', 'el Parc i la Llacuna del Poblenou', 'les Tres Torres', 'Sant Gervasi - Galvany', 'la Salut', 'Sant Gervasi - la Bonanova', 'la Vila Ol\xc3\xadmpica del Poblenou', 'el Putxet i el Farr\xc3\xb3', 'el Coll', 'Vallcarca i els Penitents', 'la Vila de Gr\xc3\xa0cia', "el Camp d'en Grassot i Gr\xc3\xa0cia Nova", 'Can Bar\xc3\xb3', 'el Guinard\xc3\xb3', 'Can Peguera', "la Font d'en Fargues", 'la Teixonera', 'Sant Gen\xc3\xads dels Agudells', 'Montbau', 'Bar\xc3\xb3 de Viver', 'el Carmel', "la Vall d'Hebron", 'Vilapicina i la Torre Llobeta', 'Porta', 'el Tur\xc3\xb3 de la Peira', 'el Poblenou', 'Horta', 'la Guineueta', 'Canyelles', 'les Roquetes', 'Verdun', 'la Prosperitat', 'el Bon Pastor', 'la Trinitat Nova', 'Torre Bar\xc3\xb3', 'Ciutat Meridiana', 'Vallbona', 'la Trinitat Vella', 'Sant Andreu', 'la Sagrera', 'el Congr\xc3\xa9s i els Indians', 'Navas', "el Camp de l'Arpa del Clot", 'Diagonal Mar i el Front Mar\xc3\xadtim del Poblenou', 'el Bes\xc3\xb2s i el Maresme', 'Proven\xc3\xa7als del Poblenou', 'Sant Mart\xc3\xad de Proven\xc3\xa7als', 'la Verneda i la Pau']

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [12]:
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.tile_providers import CARTODBPOSITRON_RETINA


source = ColumnDataSource(listings)

bound = 20000000 # meters
fig = figure(tools='pan, wheel_zoom', x_range=(-bound, bound), y_range=(-bound, bound), webgl=True)
fig.axis.visible = False
fig.add_tile(CARTODBPOSITRON_RETINA)
circles = Circle(x="longitude",y="latitude")
fig.add_glyph(source, circles)
output_file("airbnb_plot.html")
show(fig)

In [15]:
from geopandas import GeoDataFrame
from shapely.geometry import Point

In [16]:
geometry = [Point(xy) for xy in zip(listings.longitude, listings.latitude)]
df = listings.drop(['longitude', 'latitude'], axis=1)
crs = {'init': 'epsg:4326'}
geo_df = GeoDataFrame(df, crs=crs, geometry=geometry)

In [17]:
geo_df


Out[17]:
id name host_id host_name neighbourhood_group neighbourhood room_type price minimum_nights number_of_reviews last_review reviews_per_month calculated_host_listings_count availability_365 geometry
0 8207551 Room in Sant Antoni huge terrasse 7783989 Christophe Ciutat Vella el Raval Private room 39 1 2 2015-09-27 0.11 2 0 POINT (2.163839677610885 41.3808442104594)
1 14958299 Next To Las Ramblas, Unique, Wif1 48792562 Kristina Ciutat Vella el Raval Entire home/apt 60 1 15 2017-02-09 2.26 1 99 POINT (2.164465800294399 41.37971213944181)
2 7766152 Sunny whole flat in Raval/Ramblas 40843803 Maria Ciutat Vella el Raval Entire home/apt 55 2 8 2015-11-16 0.40 1 151 POINT (2.165327414236724 41.3809633214534)
3 9237132 Apartment in the heart of Barcelona 47842001 Vik Ciutat Vella el Raval Entire home/apt 99 2 55 2017-03-19 3.17 1 303 POINT (2.165550858260662 41.37778018096422)
4 1406827 Centric Bohemian next Ramblas&Macba 7573380 Croki Ciutat Vella el Raval Entire home/apt 45 2 226 2017-03-28 5.06 1 26 POINT (2.164574950324964 41.38083805260286)
5 16478595 Habitacion Single Exterior 1782585 Bruno Ciutat Vella el Raval Private room 25 1 3 2017-03-10 0.94 2 354 POINT (2.16808200194172 41.38384016737515)
6 12544567 Beautiful Apartment in City D 36978155 Exella Ciutat Vella el Raval Entire home/apt 79 3 32 2017-03-27 2.79 4 312 POINT (2.165212756886791 41.37859515524733)
7 9617892 single room 771458 Rita Ciutat Vella el Raval Private room 21 3 2 2017-01-04 0.58 9 151 POINT (2.169632418797068 41.38412485950965)
8 16119513 BOQUERIA!!!RAMBLA!!!DOUBLE ROOM FOR RENT 104665401 Angelo Ciutat Vella el Raval Private room 40 1 17 2017-04-06 3.86 2 182 POINT (2.170023193325836 41.38138352035968)
9 7487055 Apartamento para famillas Barcelona 2037915 Virginie Ciutat Vella el Raval Entire home/apt 98 4 5 2016-08-20 0.25 2 0 POINT (2.164800994532027 41.37783207754138)
10 11297010 Beautiful apt double terrace center 59035387 Alexandra Ciutat Vella el Raval Entire home/apt 60 4 23 2017-03-03 1.79 1 253 POINT (2.16421291926071 41.37921052520003)
11 14598540 Modern Loft DBL Room w/ Balcony 39741535 Stuart Ciutat Vella el Raval Private room 42 1 0 NaN NaN 1 88 POINT (2.166933873022901 41.37867518594842)
12 13924282 Lovely LOFT in el Raval (city centre) 16987668 Gery Ciutat Vella el Raval Entire home/apt 70 3 21 2017-03-12 2.34 2 28 POINT (2.164761939052871 41.37754200258407)
13 7651042 Pop Apartment next to LA RAMBLA 39452746 Pop Ciutat Vella el Raval Entire home/apt 65 1 37 2017-03-12 1.83 1 100 POINT (2.167288942143302 41.37760436606728)
14 9116045 大きく綺麗な快適ハウス。Big comfortable house 47499138 Hiroko Ciutat Vella el Raval Private room 36 2 69 2017-04-02 4.09 5 39 POINT (2.166533090481325 41.37832311427675)
15 14930754 Habitación en el centro de Barcelona 93885912 Laura Ciutat Vella el Raval Private room 55 2 1 2016-09-14 0.14 1 0 POINT (2.17188308272223 41.38148640219714)
16 9360793 Centrical room OldCity Breakfast 48575675 Eugenio Ciutat Vella el Raval Private room 27 2 50 2017-04-02 3.03 2 52 POINT (2.164494236842498 41.379222520847)
17 11396152 Flat in Raval, 3mn from Metro L3 5014487 Thibaut Ciutat Vella el Raval Entire home/apt 525 1 0 NaN NaN 1 0 POINT (2.166495246811659 41.37810234238025)
18 16890150 Habitación doble en el Raval 47491355 Mechi Ciutat Vella el Raval Private room 45 2 6 2017-03-26 2.86 1 86 POINT (2.169608416782448 41.381760325512)
19 12752928 Cosy central flat w/ terrasse 21451905 Margaux Ciutat Vella el Raval Entire home/apt 90 2 6 2016-09-18 0.54 1 1 POINT (2.166143953655235 41.38060007472559)
20 13823710 Ocio y cultura 79205431 Israel Ciutat Vella el Raval Private room 30 3 29 2017-04-04 3.20 1 16 POINT (2.163641794330918 41.38048480236209)
21 13308711 Sunny room in Raval Center 62621820 David Ciutat Vella el Raval Private room 55 1 40 2017-03-29 3.93 1 66 POINT (2.167823732077494 41.38017784536376)
22 6230160 Central double room Sunny Terrace 32322693 Niam Ciutat Vella el Raval Private room 65 3 37 2017-01-06 1.77 1 29 POINT (2.165554125755137 41.37975541288914)
23 5303197 HABITACION BALCON y CAMA DOBLE 16987393 Simone Ciutat Vella el Raval Private room 45 1 42 2017-03-20 1.87 5 347 POINT (2.169724365950019 41.38357138822411)
24 957360 CHIC BEAUTIFUL SUITE in arty centric flat 3147574 Lili Ciutat Vella el Raval Private room 60 2 114 2017-03-05 2.44 2 291 POINT (2.168691950008185 41.38371642239321)
25 9095219 COZY CENTRIC 2BD WITH LOVE 47420556 B-Mut Ciutat Vella el Raval Entire home/apt 47 3 25 2017-04-02 1.46 2 309 POINT (2.164473820237333 41.3784377789124)
26 15093459 BHNflats4u 103 94665134 Bhn Ciutat Vella el Raval Entire home/apt 75 3 0 NaN NaN 2 294 POINT (2.165956714844972 41.3773861334088)
27 11383842 Cool Flat in Barcelona Center! 59572504 Carlos Ciutat Vella el Raval Entire home/apt 120 2 31 2017-03-15 2.29 1 109 POINT (2.1677022534971 41.38042068512448)
28 17332258 Hermoso apartamento en Sant Antoni 5443088 Ruben Ciutat Vella el Raval Entire home/apt 165 3 0 NaN NaN 5 79 POINT (2.164926974104508 41.38033857619212)
29 6653123 Charming and enchanting penthouse 4789221 Ravi Ciutat Vella el Raval Entire home/apt 125 3 23 2017-03-13 1.12 1 137 POINT (2.16671759803303 41.38033751034111)
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
17623 18066180 NEW - APARTMENT PARIS 69956215 Xavi Sants-Montjuïc Sants - Badal Entire home/apt 60 1 0 NaN NaN 1 92 POINT (2.120647374443942 41.37214853921299)
17624 17977716 Habitación en el centro de Sta. Coloma de Gram... 123486164 Alejandra Sant Andreu Baró de Viver Private room 250 1 0 NaN NaN 1 100 POINT (2.206759542404205 41.45008961888274)
17625 18051979 Habitacion limpio y centrico 89206175 Ross Les Corts la Maternitat i Sant Ramon Private room 41 1 0 NaN NaN 1 365 POINT (2.11891312433082 41.37382114227098)
17626 17461980 BCN Fira luxury flat. 3br, 2bhr. Gran comfort. 34858891 Carmen Sants-Montjuïc la Marina de Port Entire home/apt 120 3 1 2017-03-22 1.00 1 187 POINT (2.127461804918392 41.3565292597192)
17627 17846338 Big lighted flat in Collblanc, for the summer 122089386 Maria Sants-Montjuïc Sants - Badal Private room 21 1 0 NaN NaN 1 282 POINT (2.123485517750253 41.3725174519848)
17628 17998475 Downtown Yacht - Apartment 38490401 Alvaro Sant Martí el Besòs i el Maresme Entire home/apt 120 1 0 NaN NaN 1 56 POINT (2.229596638041588 41.41326287756439)
17629 17799746 New and comfortable apartment next to the tube 121633485 Sandra Les Corts la Maternitat i Sant Ramon Entire home/apt 115 2 0 NaN NaN 1 142 POINT (2.109131912342785 41.37422438466317)
17630 18067318 Habitación sólo para 1. 124376637 Isabel Nou Barris Vallbona Private room 11 1 0 NaN NaN 1 319 POINT (2.182958651466414 41.47211387696906)
17631 17811715 Lovely Doble Room 9582148 Zoila Sants-Montjuïc Sants - Badal Private room 14 1 0 NaN NaN 2 146 POINT (2.122409251543729 41.3719633455119)
17632 17850961 Comfy and sunny apartment at Collblanc 2041901 Dani Les Corts la Maternitat i Sant Ramon Entire home/apt 66 3 0 NaN NaN 21 216 POINT (2.11876563757604 41.37440068541837)
17633 17950371 Collblanc. Lugar tranquilo y bien comunicado 1/2 30678793 Juan Carlos Les Corts la Maternitat i Sant Ramon Private room 30 1 0 NaN NaN 2 101 POINT (2.1175962510512 41.3746241658267)
17634 18031869 Apartamento, ✌vacaciones perfectas. 120516464 Mary Les Corts la Maternitat i Sant Ramon Entire home/apt 50 1 0 NaN NaN 2 120 POINT (2.113462193693593 41.37316359707226)
17635 17857108 Chic 1BR | Pl. España - 10min | 3.3 24350670 Rea & Eitan Sants-Montjuïc la Bordeta Entire home/apt 79 2 0 NaN NaN 17 245 POINT (2.126187646450277 41.36720598936179)
17636 17793885 Barco de Lujo en Barcelona 79276019 Elena Ciutat Vella la Barceloneta Entire home/apt 150 1 0 NaN NaN 2 364 POINT (2.198706162399361 41.38083311807142)
17637 17757377 Barcelona Marta´s Flat 2 - FC Barcelona 9590271 Marta Sants-Montjuïc Sants - Badal Entire home/apt 52 5 2 2017-03-28 2.00 2 247 POINT (2.122627103425492 41.37400169567579)
17638 17855475 Chic 1BR | Pl. España - 10min | 2.2 24350670 Rea & Eitan Sants-Montjuïc la Bordeta Entire home/apt 79 2 0 NaN NaN 17 247 POINT (2.12701618186068 41.36761595370178)
17639 17924364 Cozy and Bright Double Room 9582148 Zoila Sants-Montjuïc Sants - Badal Private room 35 1 0 NaN NaN 2 314 POINT (2.120175460980549 41.37168568597056)
17640 17712347 Chic 1BR | Pl. España - 10min | 3.2 24350670 Rea & Eitan Sants-Montjuïc Sants - Badal Entire home/apt 79 2 0 NaN NaN 17 240 POINT (2.125900045798294 41.36777708365938)
17641 17856711 Chic 1BR | Pl. España - 10min | 2.3 24350670 Rea & Eitan Sants-Montjuïc la Bordeta Entire home/apt 79 2 0 NaN NaN 17 247 POINT (2.127089765516704 41.36641326823342)
17642 18068224 Camp Nou Experience 4396136 Marisa Sants-Montjuïc Sants - Badal Entire home/apt 70 3 0 NaN NaN 5 353 POINT (2.126725410840346 41.37091273760764)
17643 17691822 Habitación luminosa y bien comunicada 120520187 Leide Sants-Montjuïc la Bordeta Private room 22 1 0 NaN NaN 1 67 POINT (2.127817261599723 41.36802138529043)
17644 17707384 Disfrutar de una estancia diferente en Barcelona 113075896 Pedro Sant Martí el Besòs i el Maresme Entire home/apt 49 3 3 2017-04-04 3.00 1 259 POINT (2.230621185765782 41.41294662376952)
17645 17783554 Beautiful Swedish Sailboat 24928953 Roland Sant Martí el Besòs i el Maresme Entire home/apt 29 1 0 NaN NaN 1 181 POINT (2.226652607256786 41.41330023308782)
17646 17567930 Cozy apartment close to Camp Nou 119270001 Smart Sants-Montjuïc Sants - Badal Entire home/apt 109 2 0 NaN NaN 1 315 POINT (2.121872496784262 41.37307277236897)
17647 17956561 Acogedor y muy cerca del estadio del Barça 118633532 Rosa Sants-Montjuïc Sants - Badal Entire home/apt 68 5 0 NaN NaN 2 42 POINT (2.121863462225591 41.37328953432665)
17648 17911853 Cozy modern 2 bedroom flat near Florida station 116489132 Maria Les Corts la Maternitat i Sant Ramon Entire home/apt 85 2 0 NaN NaN 2 108 POINT (2.108465381892105 41.37249409061476)
17649 17824939 Tu apartamiento para vacaciones perfectas. 120516464 Mary Les Corts la Maternitat i Sant Ramon Entire home/apt 50 1 0 NaN NaN 2 90 POINT (2.113320580122992 41.3736073542685)
17650 15866753 Private Double Room near Camp Nou 102056440 María Les Corts la Maternitat i Sant Ramon Private room 25 1 0 NaN NaN 1 354 POINT (2.109527912996577 41.37211240499848)
17651 17954486 Collblanc. Lugar tranquilo y bien comunicado 2/2 30678793 Juan Carlos Les Corts la Maternitat i Sant Ramon Private room 25 1 1 2017-04-02 1.00 2 100 POINT (2.117319940384607 41.37528746834418)
17652 17622319 Cozy single room 29755355 Pedro Sant Andreu Baró de Viver Private room 14 1 1 2017-03-29 1.00 1 46 POINT (2.205093513059947 41.45110876771943)

17653 rows × 15 columns


In [ ]: