import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas_profiling as pp
from sklearn.datasets import load_wine, load_iris
%matplotlib inline

# Constants
CLEAN_DATA_PATH = "../../Data/Processed/iris_csv.csv"

raw_data = load_iris()

features = pd.DataFrame(data=raw_data['data'],columns=raw_data['feature_names'])
data = features
data['target']=raw_data['target']
data['class']=data['target'].map(lambda ind: raw_data['target_names'][ind])
data.head()

data.shape

data.columns

print(raw_data['DESCR'])

data.info()

data.describe()

def check_unique(df):
    """"
    Checks the unique value in each column
    :param df: The dataframe
    """
    for col in df.columns:
        unique = df[col].unique()
        print("Column: {} has {} unique values\n".format(col, unique))

check_unique(data)

fig = plt.figure()
sns.countplot(x="target", data=data, palette="gist_rainbow_r")
plt.xlabel("Classes(0 = setosa, 1 = versicolor, 2 = verginica)")
plt.title("Target distribution")
plt.show()


data = data[data['class'] != 'virginica']

data.duplicated().sum()

data.drop_duplicates(inplace=True)

data.drop('target', axis=1).corrwith(data['target']).plot(kind='bar', grid=True, figsize=(12, 8), title="Correlation with target")

pp.ProfileReport(df=data, dark_mode=True, explorative=True)

data

data = data[['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)', 'target']]

data.to_csv(CLEAN_DATA_PATH, index=False)

