text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/diamonds/diamonds.csv')

data.dtypes

data = data.drop(data.loc[data.x <= 0].index)
data = data.drop(data.loc[data.y <= 0].index)
data = data.drop(data.loc[data.z <= 0].index)

data['ratio'] = data.x / data.y

premium = ['D', 'E', 'F', 'G', 'H']
def data_split(status):
    if status in premium:
        return 'premium'
    else:
        return 'normal'
def data_split_num(status):
    if status in premium:
        return 1
    else:
        return 0
data['data_split'] = data['color'].apply(data_split)
data['data_split_num'] = data['color'].apply(data_split_num)

#correlation matrix for 15 variables with largest correlation
corrmat = data.corr()
f, ax = plt.subplots(figsize=(12, 9))
k = 8 #number of variables for heatmap
cols = corrmat.nlargest(k, 'price')['price'].index
cm = np.corrcoef(data[cols].values.T)

# Generate a mask for the upper triangle
mask = np.zeros_like(cm, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

hm = sns.heatmap(cm, vmax=1, mask=mask, cbar=True, annot=True, square=True, fmt='.2f', annot_kws={'size': 10}, yticklabels=cols.values, xticklabels=cols.values)
plt.show()

print(' Diamond Carat = ' + str(np.mean(data.carat)))
plt.subplots(figsize=(10, 7))
sns.distplot(data.carat)
plt.show()