import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
wc = pd.read_csv("Western_Europe_City.csv")
wr = pd.read_csv("Western_Europe_Resort.csv")
base = pd.read_csv("city.csv")
bas = pd.read_csv("resort.csv")
bas1 = bas.loc[(base["continent"]=="Europe")]
print(len(bas1))
print(len(wr))
len(wr)/len(bas1)*100
base1 = base.loc[(base["continent"]=="Europe")]
base2 = base1.loc[(base1['country_decoded']=='Portugal')]
print(len(base2)/len(base1)*100)
len(wc)/len(base1)*100
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Else','Westen_Europe'
fracs = [86.20, 13.80]
labels1 = 'Else', 'Portugal','Westen_Europe'
fracs1 = [30.44,28.61,40.95]
# Make figure and axes
fig, axs = plt.subplots(1, 2,figsize = (10,5))
# A standard pie plot
axs[0].pie(fracs, labels=labels, autopct='%1.1f%%', shadow=True,
explode=(0, 0.1))
axs[0].set_title("Resort_Hotel_Market_Share")
# Shift the second slice using explode
axs[1].pie(fracs1, labels=labels1, autopct='%1.1f%%', shadow=True,
explode=(0,0,0.1))
axs[1].set_title("City_Hotel_Market_Share")
plt.show()
wc.head().iloc[:,9:20]
labels = wc.groupby(['distribution_channel'])['distribution_channel'].count().index
west_E = (wc.groupby(['distribution_channel'])['distribution_channel'].count()/len(wc)*100).round(2).iloc[0:4]
E = (base1.groupby(['distribution_channel'])['distribution_channel'].count()/len(base1)*100).round(2).iloc[0:4]
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots(figsize = (6,5))
rects1 = ax.bar(x - width/2, west_E, width, label='West Europe')
rects2 = ax.bar(x + width/2, E, width, label='Europe')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('%')
ax.set_title('Percentage by distribution channel')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
def autolabel(rects):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
fig.tight_layout()
plt.show()
labels = wc.groupby(['market_segment'])['market_segment'].count().index
west_E = (wc.groupby(['market_segment'])['market_segment'].count()/len(wc)*100).round(2).iloc[0:]
E = (base1.groupby(['market_segment'])['market_segment'].count()/len(base1)*100).round(2).iloc[0:]
x = np.arange(len(labels)) # the label locations
width = 0.25 # the width of the bars
fig, ax = plt.subplots(figsize = (13,7))
rects1 = ax.bar(x - width/2, west_E, width, label='West Europe')
rects2 = ax.bar(x + width/2, E, width, label='Europe')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('%')
ax.set_title('Percentage by Market Segment')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
def autolabel(rects):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
fig.tight_layout()
plt.show()
agent = (wc.groupby(['agent'])['hotel'].count()/len(wc)*100).round(2).to_frame().sort_values(by = 'hotel', ascending=False)
agent.head(10)
agent = (wr.groupby(['agent'])['hotel'].count()/len(wr)*100).round(2).to_frame().sort_values(by = 'hotel', ascending=False)
agent.head(10)
for i in ([9,14,7,28]):
wc1 = wc.loc[(wc['agent'] == str(i) )]
print(i,wc1['market_segment'].value_counts())