text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

data = pd.read_csv('../input/wine-quality-dataset/WineQT.csv')

data.corr()

data.columns

data = data.drop(['Id'], axis=1)

f,ax=plt.subplots(figsize=(18,9))
sns.heatmap(data.corr(),annot=True,linewidths=5,fmt='.1f',ax=ax,linecolor='black')

data.rename(columns={'fixed acidity': 'fixed_acidity', 'volatile acidity': 'volatile_acidity', 'citric acid': 'citric_acid', 'residual sugar': 'residual_sugar', 'free sulfur dioxide': 'free_sulfur_dioxide', 'total sulfur dioxide': 'total_sulfur_dioxide'}, inplace=True)
data.columns

data['evaluation'] = ['Bad' if i < 3 else 'Good' if i < 7 else 'High quality' for i in data.quality]
data.loc[:15, ['quality', 'evaluation']]

quality_list = list(data.quality.unique())
sulfur = []
for i in quality_list:
    x = data[data.quality == i]
    sulfur_rate = sum(x.quality) / len(x)
    sulfur.append(sulfur_rate)
dataFrame = pd.DataFrame({'quality_list': quality_list, 'sulfur_ratio': sulfur})
new_index = dataFrame['sulfur_ratio'].sort_values(ascending=False).index.values
sorted_data2 = dataFrame.reindex(new_index)
plt.figure(figsize=(15, 10))
sns.barplot(x=sorted_data2['quality_list'], y=sorted_data2['sulfur_ratio'])
plt.xticks(rotation=90)
plt.xlabel('quality')
plt.ylabel('sulfur rate')
plt.show()