"""
**Brief Information:** One of the biggest e-commerce company in Turkey called "Trendyol" (www.trendyol.com) sells books online. This dataset is scraped from their ranked mostly liked books page. We will analyse the books, authors, prices, publishers, sellers and their ranks to understand why they are the most liked ones.
"""
#importing libraries
import requests
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
import re
import seaborn as sns
import matplotlib.pyplot as plt
#importing data
data= pd.read_excel('../input/booksdata/books2.xlsx')
data
data.info()
"""
We don't have any missing values. Price is not float, so we should change this.
"""
for i in range(data.shape[0]):
    data["Price"][i]= data["Price"][i][:-2].replace(",",".")
data["Price"]= data["Price"].astype(float)
data["Price"]
"""
### Numeric Values Statistics
"""
data.describe()
"""
Seller ranks are around 9 which is good to know. Prices have high standard deviation 5 turkish lira to 197. 
"""
#correlation and visualization
print(data.corr())
sns.regplot(data["Price"], data["Seller Rank"])
plt.show()
"""
Their correlation is not high and significant.
"""
#histograms and scatter plots
sns.pairplot(data)
"""
Price histogram shows us there is a high price value (an outlier), and the others have less standard deviation without it. We can see this from the boxplot below.
"""
plt.figure(figsize = (6, 4))
sns.boxplot(data["Price"])
#printing the outlier's features
from scipy import stats
z = np.abs(stats.zscore(data["Price"]))
data.loc[data["Price"][(z > 2)].index]
data.loc[data["Price"][(z < 2)].index]["Price"].describe()
"""
The mean of prices decreased to 20 and the standar deviation decreased from 19 to 9 which is expected.
"""
"""
### Price vs Seller Effect
"""
data2= data[data.Seller.isin(data["Seller"].value_counts().index[:10])]
plt.figure(figsize = (14, 10))
ax = sns.boxplot(x="Seller", y="Price", data=data2)
plt.setp(ax.artists, alpha=.5, linewidth=2, edgecolor="k")
plt.xticks(rotation=45)
"""
### Categorical Features Visualization
"""
sns.barplot(data["Author"].value_counts().index[:10],data["Author"].value_counts().values[:10] )
plt.xticks(rotation=90)
plt.grid(alpha=0.2)
plt.title("Authors' Rate")
plt.show()
sns.barplot(data["Publisher"].value_counts().index[:10],data["Publisher"].value_counts().values[:10] )
plt.xticks(rotation=90)
plt.grid(alpha=0.2)
plt.title("Publishers' Rate")
plt.show()
"""
For authors and publishers, there is no by far the leading.
"""
sns.barplot(data["Seller"].value_counts().index[:10],data["Seller"].value_counts().values[:10] )
plt.xticks(rotation=90)
plt.grid(alpha=0.2)
plt.title("Sellers' Rate")
plt.show()
"""
As we can see, the publisher named "Kırmızı Kedi Kitapevi" has the majority in all different options.
"""
#let's visualize it

a= list(data["Seller"].value_counts().values[:10] /data.shape[0])
a.append(1-np.sum(list(data["Seller"].value_counts().values[:10] /data.shape[0])))
b= list(data["Seller"].value_counts().index[:10])
b.append("Other")

plt.rcParams["figure.figsize"] = (25,15)
theme = plt.get_cmap('hsv')

explode = (0.1,0,0,0,0,0,0,0,0,0,0)  

fig1, ax1 = plt.subplots()
theme = plt.get_cmap('jet')
ax1.set_prop_cycle("color", [theme(1. * i / len(a)) for i in range(len(a))])

ax1.pie(a, explode=explode, labels=b, autopct='%1.1f%%',
        shadow=True, startangle=90, textprops={'fontsize': 16})
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
plt.title("Sellers' Total Rate", fontsize=20)
plt.show()
"""
Conclusion: After analysing all features, authors & publishlers have no dominant one comparing the others. Prices are around 20 turkish liras with 9 standard deviation. Also dataset proved us the most significant thing we see is the seller of books is 'Kırmızı Kedi Kitabevi' with %65 possibility. Seller is the feature we should consider about.
"""