#Dataset from Airbnb showing the listings for London (date: March 3017)
airbnb = pd.read_csv('https://raw.githubusercontent.com/borja876/Thinkful-DataScience-Borja/master/listings.csv')
df = pd.DataFrame(airbnb)

#Distribution of the variable price
sns.distplot(df['price'])
plt.xlim([0, 600])
plt.title('More frequent prices (GBP)')

#A random distribution has been created and plotted
x = np.random.normal(size=1000)
sns.distplot(x)

#Desnity function showing the bins that have been used to plot it
sns.distplot(x, hist=False, rug=True)

#Plot of a gamma distribution
x = np.random.gamma(2, size=200)
sns.distplot(x, kde=False, fit=stats.gamma)

"""
Explanation: Choose one variable and plot that variable four different ways
End of explanation
"""


#The dataset of Airbnb has been cleaned leaving only the 4 variables that are required for plotting
df = pd.DataFrame(airbnb)
df1 = df.drop(["id", "name", "host_id", 'host_name', 'neighbourhood','neighbourhood_group', 'latitude', 'longitude', 'room_type', 'last_review', 'calculated_host_listings_count','reviews_per_month' ], axis=1)
df1.head()

#Plot the relationship between availability and price
g = sns.lmplot(x="price", y="availability_365", col="room_type", data=df)
plt.xlim([0, 1000])
plt.ylim([-50, 500])

#Dropped the minimum nights and number of reviews to avoid problems. Plot the distributions and bivariate relation between both variables
df2 = df1.drop(['minimum_nights','number_of_reviews'], axis=1)
# Set style of scatterplot
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")

# Create scatterplot of dataframe
sns.pairplot(df2)

# title
plt.title('Relationship between Price (GBP) and availability (Days)')

#Density regions for the relationship between availability and price
sns.jointplot("price", "availability_365", data=df2, xlim=250, ylim=None, kind="kde")

"""
Explanation: Choose two continuous variables, and plot them three different ways
End of explanation
"""


#Bar plot with error of the categorical variable: room type and price
sns.set(style="whitegrid")

# Draw a nested barplot to show prices per room type in Airbnb
g = sns.factorplot(x="room_type", y="price", data=airbnb, size=4, kind="bar", palette="muted")
g.despine(left=True)
g.set_ylabels("prices")
plt.ylim([0, 250])
plt.title('Price (GBP) per room type')

#Boxplot 
#Show price per room type in horizontal boxplot with log scale
sns.set(style="ticks")

# Initialize the figure with a logarithmic x axis
f, ax = plt.subplots(figsize=(7, 6))
ax.set_xscale("log")

# Plot the price with horizontal boxes
sns.boxplot(x="price", y="room_type", data=airbnb, whis=np.inf, palette="vlag")

# Add in points to show each observation
#sns.swarmplot(x="price", y="room_type", data=airbnb, size=2, color=".3", linewidth=0)

# Tweak the visual presentation
ax.xaxis.grid(True)
ax.set(ylabel="")
sns.despine(trim=True, left=True)
plt.title('Price (GBP) per room type')

#Histogram to see the frequency of pricese per room type
g = sns.FacetGrid(df, col="room_type")
g.map(plt.hist, "price")
plt.xlim([0, 1000])
plt.ylim([0, 30000])
plt.title('Prices (GBP) per room type')

#Count the number of instances for each room type
sns.countplot(x="room_type", data=df, palette="Greens_d")

#Show the prices with a stripplot
sns.stripplot(x="room_type", y="price", data=df, jitter=True)
plt.ylim([0, 500])
plt.title('Prices (GBP) per room type')

#Count the number of instances for each type of room with a horizontal bar plot
f, ax = plt.subplots(figsize=(7, 3))
sns.countplot(y="room_type", data=df, color="c")

"""
Explanation: Choose one continuous variable and one categorical variable, and plot them six different ways
End of explanation
"""


#Clean the Airbnb dataset by dropping all the varibles that are unrelated to the challenge
df3 = df.drop(["id", "name", "host_id", 'host_name', 'neighbourhood','neighbourhood_group', 'latitude', 'longitude', 'last_review', 'calculated_host_listings_count','reviews_per_month' ], axis=1)
df3.head()

g = sns.pairplot(df3, hue="room_type", diag_kind="hist")  
for ax in g.axes.flat:  
    plt.setp(ax.get_xticklabels(), rotation=45)

"""
Explanation: Challenge
End of explanation
"""


