"""
# RAMEN RATINGS PROJECT
"""
"""
### SOME QUESTIONS TO ANSWER WITH DATA VISUALIZATION:
- What are the Top ten rated ramens?
- What the country with the highest rating product?
- What country produces the highest amount of ramen products?
- Which brands are the most successful? 
- Which style has the best ratings?

"""
"""
#### This data set is from following Kaggle link: 
https://www.kaggle.com/residentmario/ramen-ratings
"""
### Import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('../input/ramen-ratings/ramen-ratings.csv')
data.head(10)
data.info()
data.describe(include='all')
"""
## Top Ten Ramens
"""
data_top_ten = data[data['Top Ten'].notnull()]
data_top_ten
top_tens = data_top_ten[data_top_ten["Top Ten"] != '\n']
top_tens
top_tens['Year'] = top_tens['Top Ten'].apply(lambda year:year.split('#')[0])
top_tens['Rank'] = top_tens['Top Ten'].apply(lambda year:int(year.split('#')[1]))
top_tens['Popularity'] = top_tens['Rank'].apply(lambda rank: abs(11-rank))
top_tens
top_tens =top_tens.drop('Top Ten',axis=1)
top_tens.head()
top_tens = top_tens.drop('Review #',axis=1)
top_tens.reset_index(drop=True)
## 2016 top ten ramen
plt.figure(figsize=(14,4)) 

sns.countplot(data=top_tens,x='Country',hue='Rank')
plt.legend(loc=(1.05 ,0.1),title="Ranks")
## 2016 top ten ramen
tops = sns.catplot(data=top_tens,x='Country',y='Popularity',hue='Year',kind='bar',height=6,aspect=2,ci=None)
(tops.set_axis_labels('COUNTRIES', 'MOST RANKED',weight='bold')
     .set(ylim=(0,10)))
tops.fig.suptitle('MOST RANKED RAMEN BY COUNTRY AND YEAR',weight='bold')
"""
### Sorting Top Tens Dataframe based on rank for each year for easy reading
"""
top_tens= top_tens.sort_values(by=['Year','Rank'],ascending=True,ignore_index=True)
top_tens
plt.figure(figsize=(16,10))
sns.countplot(data=top_tens,x='Country').set_title('Best Countries in Top Ten Ramen List',weight='bold')

plt.figure(figsize=(10,6))
sns.countplot(data=top_tens,x='Style').set_title('Best Styles in Top Ten Ramen List',weight='bold')
"""
### What country has the most ramen products
"""
## Check if any country used by different names
data['Country'].value_counts()
data_clean = data.replace({'Country': {'United States': "USA", 'Holland': 'Netherlands', "Sarawak": 'Malaysia'}})
data_clean['Country'].value_counts()
plt.figure(figsize=(20,16),dpi=200)
ax = sns.countplot(data=data_clean, x='Country',order=data_clean['Country'].value_counts().index)
plt.title('Countries based on Ramen Products',weight='bold',fontsize=16)    
plt.xlabel('Countries',weight='bold')
plt.xticks(rotation=90)

for p in ax.patches:
    ax.annotate(f'\n{p.get_height()}', (p.get_x()+0.2, p.get_height()), ha='center', va='top', color='black', size=10)
plt.show()
"""
### Which brands are the most successful?
"""
data_clean['Stars'].value_counts()
drop_unrated = data_clean[data_clean['Stars'] == 'Unrated'].index
data_clean = data_clean.drop(drop_unrated)
data_clean['Stars'] = data_clean['Stars'].apply(lambda star: float(star))
successful_brands = data_clean[ data_clean["Stars"] >= 4.5]
successful_brands['Brand'].value_counts()
## There are lots of brands (147) with 4.5 star and above, so I will display only the first 10 companies with most stars
plt.figure(figsize=(20,10))
ax = sns.countplot(data=successful_brands, x='Brand', hue='Stars', order = successful_brands['Brand'].value_counts().iloc[:10].index)
plt.title('Most Successful Ten Ramen Brands based on Stars',weight='bold',fontsize=16)
plt.xlabel('Brand Name',weight='bold')
plt.ylabel('Count',weight='bold')
plt.xticks(rotation=90)
for p in ax.patches:
    ax.annotate(f'\n{p.get_height()}', (p.get_x()+0.2, p.get_height()), ha='center', va='top', color='black', size=10)
plt.show()
"""
### Which style has most ratings?
"""
## I will use successful_brands df for styling, because I already distrubuted ramens by 4.5 stars and above
successful_brands['Style'].value_counts()
plt.figure(figsize=(20,10))
ax = sns.countplot(data=successful_brands, x='Style', hue='Stars', order = successful_brands['Style'].value_counts().index)
plt.title('Most Rated Styles',weight='bold',fontsize=16)
plt.xlabel('Brand Name',weight='bold')
plt.ylabel('Count',weight='bold')
plt.xticks(rotation=90)

plt.show()