text_plain_output_1.png
import numpy as np

import pandas as pd

import os
data = pd.read_csv('/kaggle/input/heart-disease/heart.csv')

data.shape

data.columns

data.nunique()

data.dtypes

data.loc[data['ca'] == 4, 'ca'] = np.NaN

data.loc[data['thal'] == 0, 'thal'] = np.NaN

data.isnull().sum()

data.isnull().sum()

data.duplicated().sum()

data[data.duplicated()]

data = data.drop_duplicates(keep='first')
data

data.duplicated().sum()

continous_features = ['age', 'trestbps', 'chol', 'thalach', 'oldpeak']
def outliers(data_out, drop=False):
    for each_feature in data_out.columns:
        feature_data = data_out[each_feature]
        Q1 = np.percentile(feature_data, 25.0)
        Q3 = np.percentile(feature_data, 75.0)
        IQR = Q3 - Q1
        outlier_step = IQR * 1.5
        outliers = feature_data[~((feature_data >= Q1 - outlier_step) & (feature_data <= Q3 + outlier_step))].index.tolist()
        if not drop:
            print('For the feature {}, No of Outliers is {}'.format(each_feature, len(outliers)))
        if drop:
            data.drop(outliers, inplace=True, errors='ignore')
            print('Outliers from {} feature removed'.format(each_feature))
outliers(data[continous_features])